.NET Framework Bookmark and Share   
 index > Regular Expressions > Split two numbers with delimiter
 

Split two numbers with delimiter

Hi everybody!

I hope i need something very simple (this is my first attempt using Regex).
Problem (by example):
1232|4545 : should be split into 1232 and 4545 (delimiter char "|" should be ignored)
454656 : should be "split" into 454656

I already used the following pattern ([1-9][0-9]*)([|]([1-9][0-9]*))? to validate if a given string matches which works great, but i face problems to split the string.
How can i achieve this?

Thanks in advance!
Savvas Sopiadis
Since you already have verified the string format with the regex, the string can be split with either string.Split('|');
Les Potter, Xalnix Corporation, Yet Another C# Blog
  • Proposed As Answer byJohnGrove Thursday, August 27, 2009 9:25 PM
  • Marked As Answer bySavvas Sopiadis Sunday, August 30, 2009 6:36 PM
  •  
xalnix
Since you already have verified the string format with the regex, the string can be split with either string.Split('|');
Les Potter, Xalnix Corporation, Yet Another C# Blog
  • Proposed As Answer byJohnGrove Thursday, August 27, 2009 9:25 PM
  • Marked As Answer bySavvas Sopiadis Sunday, August 30, 2009 6:36 PM
  •  
xalnix
I think no need of Regex here at all.
Most language's built-in string functions can do such a split.
For example in VB
Dim strs() as string
Dim str as string
Dim i as integer

strs = split(str,"|")
for i = 0 to ubound(strs)
    debug.print strs(i)
next

if you need the result in one array, you may need an array to store the result
instead of printing it out.

VB has a native split function, while other languages may need write str.split("|") like xalnix wrote.
(asa method of any string virable.)


www.wonderstudio.cn
Eping Wang
Thanks everybody for the replies!

In the meantime i figured out myself that i have to use string.split(), but was curious if there is another way of doing this! (your posts are showing me that i am on the right path, since the MS platform and C# are new territory for me)

Thanks again for your time
Savvas Sopiadis

You can use google to search for other answers

Custom Search

More Threads

• Newbie question: I would like a RegEx expression to return "true" if a string value has a match for any of several possible values
• Trouble Writing a regex
• Retrieve html
• Can any one explain me more about Regular expressions in C#
• Oddity replacing newlines with <br /> tags
• Regular Expression for US and International Phone Numbers
• Looking for help with regex date format
• Regular Expressions
• .net alternative to \Q \E (which denotes a literal string in a pattern in some flavours of RegEx)
• Math symbol or checking for math symbols