Copy characters to another buffer

flynn

Regular
Joined
Jul 28, 2005
Messages
59
I know the following code doesn't work (.Chars is read-only), but hopefully you'll understand what I am wanting to do:

I want to cycle through sBuffer to remove certain QUOTE characters that are contained within certain phrases. Is there a method that is writable that I can copy the valid characters into? Something similar to the .Chars method, but also writable.

Code:
While iOldIndx < iFileLength
      If (sBuffer.Chars(iOldIndx) <> """") Then
           'keep this character by copying to the new buffer
           sNewBuf.Chars(iNewIndx) = sBuffer.Chars(iOldIndx)
           iNewIndx += 1
      End If
      iOldIndx += 1
End While

tia,
flynn
 
Last edited:
I think maybe the answer to my question is to use a StringBuilder. The .Chars method is read/write.
 
You could simply amend the new char to the end of a string for example
Visual Basic:
Dim sNewString as String = ""
While iOldIndx < iFileLength
      If (sBuffer.Chars(iOldIndx) <> """") Then
           'keep this character by copying to the new buffer
           sNewString += sBuffer.Chars(iOldIndx)
      End If
      iOldIndx += 1
End While
however if your buffer is over a few chars long (which i'm assuming it will always be), then you should do as you say and use the string builder.
 
You could also create a Char array. The string class has a ToChars function which returns the string in the form of a Char array, and a char array can be cast to a string (at least in VB). A Char array will have less overhead, but the StringBuilder is probably easier.
 
Back
Top