i have a string and want to split it at the spaces so i used the following code from the microsoft site:
i m using visual basic 6.0. the variables cudnt be initialized where they were difined so i manipulated the code as
y does this happen?? and it still shows invalid wualifier for TestArray.Lengt h..is there any other way to find the length so dat we cud run the loop ftill dat value only???? i did try len(TestArray) and GetLength(TestA rray) but to no avail
Code:
Dim TestString As String = "apple pear banana " Dim TestArray() As String = Split(TestString) ' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""} Dim LastNonEmpty As Integer = -1 For i As Integer = 0 To TestArray.Length - 1 If TestArray(i) <> "" Then LastNonEmpty += 1 TestArray(LastNonEmpty) = TestArray(i) End If Next ReDim Preserve TestArray(LastNonEmpty) ' TestArray now holds {"apple", "pear", "banana"}
Code:
Dim TestString As String TestString = "apple pear banana " Dim TestArray() As String TestArray() = Split(TestString) ' TestArray holds {"apple", "", "", "", "pear", "banana", "", ""} Dim LastNonEmpty As Integer Dim i As Integer LastNonEmpty = -1 For i = 0 To TestArray.Length - 1 'THE ERROR LINE If TestArray(i) <> "" Then LastNonEmpty = LastNonEmpty + 1 TestArray(LastNonEmpty) = TestArray(i) MsgBox TestArray(LastNonEmpty) End If Next ReDim Preserve TestArray(LastNonEmpty) ' TestArray now holds {"apple", "pear", "banana"}
Comment