How to use the Regex.Split() to split strings in C# ?
As you might know the string Split method allows you to split a string only be a specified character. If you wish to split a string using the power of the regular expressions to specify the delimiter a good solution is to use the Regex.Split() method
using System.Text;
using System.Text.RegularExpressions;
...
string strText=" DotnetSpider@@ Spider@@ Is @@ Good @@ for @@ Learner ";
foreach(string strItem in Regex.Split(strText,"@@")){
Console.WriteLine(strItem);
}
will print:
Dotnet
Spider
Good
for
Learner
using System.Text;
using System.Text.RegularExpressions;
...
string strText=" DotnetSpider@@ Spider@@ Is @@ Good @@ for @@ Learner ";
foreach(string strItem in Regex.Split(strText,"@@")){
Console.WriteLine(strItem);
}
will print:
Dotnet
Spider
Good
for
Learner
Labels: Regular Expression

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home