06-04-2010, 08:49 PM
You can also use regular expressions.
This pattern means: 3 sets of numbers of any length separated by a "," or ":" then a final set of numbers of any length.
Changing the separator or adding alpha characters or adding/removing a separator with digits will return a false.
The "Test" method returns a boolean based on the pattern. The "Execute" method will return an array of characters that match in the pattern that you can then parse to get a particular value or concatenate to return the string.
Regular expressions are quite powerful and can be used for many applications in parsing strings.
Code:
Dim re, teststring, testresults, showresults
teststring = "10:2:3:1"
Set re = new regexp
re.Pattern = "(\d*[,|:]){3}(\d*)+"
re.Global = true
re.IgnoreCase = true
'boolean test
msgbox re.Test(teststring)
'Get the actual text
set testresults = re.Execute(teststring)
For each match in testresults
showresults = showresults + match.value
Next
msgbox showresults
This pattern means: 3 sets of numbers of any length separated by a "," or ":" then a final set of numbers of any length.
Changing the separator or adding alpha characters or adding/removing a separator with digits will return a false.
The "Test" method returns a boolean based on the pattern. The "Execute" method will return an array of characters that match in the pattern that you can then parse to get a particular value or concatenate to return the string.
Regular expressions are quite powerful and can be used for many applications in parsing strings.