While .NET strings do not have a terminating character as such, the
nullchar will act like one if the string is displayed. Like this...
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button3.Click
Dim tstr As System.String = "ABCDEFGHJKLMN"
Dim newchar As Char
Dim bbyte() As Byte = {0}
newchar = System.Text.Encoding.ASCII.GetChars(bbyte)(0)
tstr = tstr.Replace("D", newchar)
System.Windows.Forms.MessageBox.Show(tstr)
-->> shows "ABC"
System.Windows.Forms.MessageBox.Show(tstr.Length.T oString)
-->> shows "13"
System.Windows.Forms.MessageBox.Show(tstr.IndexOf( newchar).ToString)
-->> shows "3"
End Sub
So while the string itself will hold the extra characters, the normal
way of showing it will not display past the nullchar.
The above code is a bit of a stretch to prove a point, but it can
happen while working with some API's that use string buffers passed
byref, communications when you have a buffer to fill and you only get
a partial message, etc.
You need to find where the end of the string that you want is located
and that is where you would use String.IndexOf
HTH,
Barry
On Tue, 18 Oct 2005 18:41:30 +0200, "Bob Powell [MVP]"
<bob@_spamkiller_bobpowell.net> wrote:
You don't need to test for the end because the length of the string is
provided. .NET strings do not have a terminating character. All the
characters in the string's character array are valid.
bceggersATcomcastDOTnet