-
Is there a resource for looking at examples of advanced string manipulations? I am looking for topics such as splitting strings, regular expression matching, splitting a string into an array, looping though an array where the size is unknown, and reading a string characterby character.
I am still getting adjsuted to VB and using the MSDN cd as a reference but a lot of the runctions I have found look extremely inefficient without saving much code writing.
-
To split strings into an array, use the Split() function:
Code:
MyString = "One,Two,Three,Four"
MyStringArray = Split(MyString, ",")
For I = 0 To UBound(MyStringArray)
Print MyStringArray(I)
Next I
To read a string character by character, use the Mid() function:
Code:
MyString = "One,Two"
For I = 1 To Len(MyString)
tChar = Array(Mid(MyString, I, 1))
Print tChar(I)
Next I
To match, use the Like operator:
Code:
MyString = "Onetwothree"
If MyString Like "*two*" Then
Print "String is found"
Else
Print "String is not found"
End If
-
//------------------
MyString = "One,Two"
For I = 1 To Len(MyString)
tChar = Array(Mid(MyString, I, 1))
Print tChar(I)
Next I
//-----------------
Why the use of Array() ? It appears to be not needed by my MSDN CD difinition.
Thanks
jon
-
Sorry, that was a mistake. To make it work properly, omit the Array function from the statement.
Code:
MyString = "One,Two"
For I = 1 To Len(MyString)
tChar = Mid(MyString, I, 1)
Print tChar(I)
Next I