I am working with visual basic.net 1.1. I need to parse out data in a string
that is space delimited. The number of spaces between each data item in the
string can change. (I have no control over how many spaces are between each
item in the string since I am getting the data from a mainframe system over
the internet.)
I know that if I used the string function called split, I can split the
items in the string into items in an array. However, this is assuming the
delimiter is exactly the same. In this case, the number of spaces can change.
Thus I am looking for a solution to this parsing problem. I do not care if
I used the split string function. I would just like a solution that works.
Thanks!
Scott M. - 03 Nov 2005 05:03 GMT
Just use split and then loop through the resulting array only paying
attention to array elements who's legnth is greater than zero.
>I am working with visual basic.net 1.1. I need to parse out data in a
>string
[quoted text clipped - 14 lines]
> works.
> Thanks!
Sherif El-Metainy - 03 Nov 2005 16:51 GMT
Hello,
Here is how to achieve it (using c# syntax). It should be easy to convert it
to VB syntax
System.Text.RegularExpressions.Regex.Split(yourInputString, @"\s+");
check the regex class and regular expressions documentation for more info.
best regards,
Sherif
>I am working with visual basic.net 1.1. I need to parse out data in a
>string
[quoted text clipped - 14 lines]
> works.
> Thanks!
David Farr - 03 Nov 2005 17:10 GMT
Better yet, use Regex to reduce all multiple spaces in the source string to
single, then use split:-
(using System.Text.RegularExpressions;)
string result = SourceString;
while(Regex.IsMatch(result," ") // double space
{
result = Regex.Replace(result, " ", " "); // replace double with
single
}
Voila!
Dave