Hi All,
I have a string in following format
abc;h=v8/35bf/3/0/*/k;
In above string I need to replace everything that comes between two ";" (semi colon), moreover the length between these two ";" can vary
I need to replace the above string with...
abc;junk;
Thanks
Nikesh
Help ... String replacement with Regex
Started by nikesh, Aug 31 2007 01:38 AM
2 replies to this topic
#1
Posted 31 August 2007 - 01:38 AM
|
|
|
#2
Posted 31 August 2007 - 04:39 AM
I never use Regex for replacment, just parseing. However, the lookup query will be ;*.; which will grab everything between the semicolens.
#3
Posted 14 September 2007 - 11:11 AM
I agree with TkTech, I wouldn't use regex to do what you want to do. I would do something like this:
Anyway, with regex you would do it something like this:
private string replace(string value)
{
string[] valueSplit = value.Split(';');
valueSplit[1] = "junk";
return String.Join(";", valueSplit);
}
Anyway, with regex you would do it something like this:
private string replace(string value)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(";.*;");
return regex.Replace(value, ";junk;");
}


Sign In
Create Account

Back to top









