»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
function to add a string at a specified match in a string using regular expressionsfunction to add a string at a specified match in a string using regular expressions
this function helps you to add a specified piece of string exactly after a match
private string CreateBreaks(string str , int count , string replacestring)
{
string dummy;
string pattern = "(.*?),";
int i = 0;
StringBuilder sb = new StringBuilder();
string[] txt;
bool flag = false;
foreach (Match m in Regex.Matches(str, pattern))
{
i++;
dummy = m.ToString();
if(i == 3)
{
dummy = dummy.Replace(",",replacestring);
i=0;
flag = true;
}
sb.Append(dummy);
}
if(flag)
{
txt = str.Replace(" ","").Split(',');
str = txt[txt.Length-1];
sb.Append(str);
}
return sb.ToString();
} |
|