John,
'\0' is a char literal in C#, VB.NET uses "x"c for char literals,
unfortunately VB.NET does not have any escaped characters.
However! VB.NET does have the ControlChars class that lists a number of
common escaped characters, such as ControlChars.NullChar, alternatively you
can simply use Chr(0) or ChrW(0).
So in VB.NET you can use either:
Dim str As String = New String(arr).Trim(ControlChars.NullChar)
Or I would consider:
Dim length As Integer = Array.IndexOf(arr, ControlChars.NullChar)
Dim str = New String(arr, 0, length)
Depending on the expected size of the strings the second might be better in
that it does not allocate 2 string objects, causing extra work for the GC.
For short strings I suspect the difference would be immaterial... Based on
extensive profiling I would pick one over the other...
Hope this helps
Jay
"John Smith" <jo********@x-formation.com> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...
Lets say I was given a Char array as:
Dim Arr(size) As Char
and this array holds a string which ends with a C-Style zero termination.
I want to make this into a String object and cut it off at the end.
So in C# I could do:
String str = (new String(arr)).Trim('\0');
However in VB '\0' is not understood.
Please advice.
-- John