Char Array to String in VB.NET 2.0
Written by Zealus on April 22, 2009 – 3:29 pm -You will be surprised, but the obvious
Dim arrChars(10) As Char Dim strString As String strString = "ABCDEFGHIK" arrChars = strString.ToCharArray strString = arrChars.ToString
Will not yield the same string as there was before. It will, rather, return “Char[]” response. To get your string back from Char Array (at least in VB.NET 2.0) you will need to call CStr on array:
Dim arrChars(10) As Char Dim strString As String strString = "ABCDEFGHIK" arrChars = strString.ToCharArray strString = Cstr(arrChars)
Funny, isn’t it? And totally counter-intuitive
Tags: .net, microsoft, programming, vb.net
Posted in annoyances, programming | 2 Comments »
June 25th, 2009 at 5:10 am
This unexplained behavior may be due to the different way in which C and C++ handle string arrays.
June 26th, 2009 at 9:23 am
What does it have to do with VB.NET?