|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to use Regex to Parse this StringHi,
I would like to know how to use Regular Expressions to iteratively return and print the items between the colons in the following string to say the console.. Any help would be appreciated. strInputString = "2:Blue:Green:1,2" Regards, Michael Murphy I would just use the Split method of the string class, and split by the ':'
character. That returns an array of strings. Show quoteHide quote "Michael D Murphy" <mdmur***@scs-techresources.com> wrote in message news:%23Ve8Fg4OFHA.3788@tk2msftngp13.phx.gbl... > Hi, > I would like to know how to use Regular Expressions to iteratively return > and print the items between the colons in the following string to say the > console.. > Any help would be appreciated. > strInputString = "2:Blue:Green:1,2" > Regards, > Michael Murphy > Hi Marina,
Thanks for the post, but I was trying to get a little introduction to Regular Expressions and thought this might be a way to start. Michael Show quoteHide quote "Marina" <someone@nospam.com> wrote in message news:ejpKPl4OFHA.3880@tk2msftngp13.phx.gbl... >I would just use the Split method of the string class, and split by the ':' >character. That returns an array of strings. > > "Michael D Murphy" <mdmur***@scs-techresources.com> wrote in message > news:%23Ve8Fg4OFHA.3788@tk2msftngp13.phx.gbl... >> Hi, >> I would like to know how to use Regular Expressions to iteratively return >> and print the items between the colons in the following string to say the >> console.. >> Any help would be appreciated. >> strInputString = "2:Blue:Green:1,2" >> Regards, >> Michael Murphy >> > > Hi Michael,
If we wants to split the string into substring. We will use the split function, which is also a static function of RegEx function. Dim strInputString As String = "2:Blue:Green:1,2" For Each str As String In Regex.Split(strInputString, ":") Debug.WriteLine(str) Next Here the regex pattern is the :, the regex will match the pattern in the second parameter of the Split method and then split the string from that position. Also we can use the regex to match the substring which did not contain :, which seems to be an indirect thinking. Dim strPattern As String = "[^:]+" For Each mt As Match In Regex.Matches(strInputString, strPattern) Debug.WriteLine(mt.Value) Next Here is a link about the special character in regex for your reference. Character Classes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht ml/cpconcharacterclasses.asp Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
DataReader in Excel (Better Post than the last)
getting row index of dataset Howto: use mutliple languages C++ in VB.net Update for VS .NET 2003? Compiler errors due to temp file inconsistencies ?? Remove items from listbox Object reference not set to an instance of an object. How to get assembly file info? cast sortedlist value as hashtable Optimization |
|||||||||||||||||||||||