Memoirs of an IT Consultant

Friday, April 21, 2006

Stringtokenizer on .NET --> Regex.Split

I have been looking at java throughout my academic days and the switch to .NET at work somehow cripples my programming skills. Different syntax, takes some time getting used to.

I was looking to ‘tokenize’ a string with a whole word as delimiter but could find almost zero resolution after google-ing for half a day. Finally, I found the answer, an amazing one as well, here. Amazing Splits. Have a read and you will find out almost everything about splitting strings in VB and VB.NET.

The answer to my problem was to use the Split method from System.Text.RegularExpressions.Regex
Regex is like the Scanner of java.

Here’s some sample coding which saved my day.
Note that I intentionally put ‘br’ into the string as well to test if it would extract ‘br’ as well like the VB Split method.

Here’s the result of my test. Rejoice~! Problem solved!

firstbrString-----secondbrString-----


You can be sure I will only be using this splitter from this day on!

0 Comments:

Post a Comment

<< Home