Reputation: 73
For example => iddaa///news/haber05112013.jpg
Result=> iddaa/news/haber05112013.jpg
I want to replace this spesific characters ("/"); But sometimes double characters ('///') , sometimes ('//') can ı replace this? Thank you
Upvotes: 4
Views: 158
Reputation: 32571
You may use a regular expression. Try this:
var strTargetString = @"iddaa///news/haber05112013.jpg";
var strRegex = @"/+";
RegexOptions myRegexOptions = RegexOptions.Multiline;
Regex myRegex = new Regex(strRegex, myRegexOptions);
var strReplace = @"/";
var result = myRegex.Replace(strTargetString, strReplace);
Upvotes: 0
Reputation: 727027
If you don't know how many repetitions there are, use Regex.Replace
:
var res = Regex.Replace(orig, "/+", "/");
"/+"
is a regular expression that matches one or more forward slash.
Upvotes: 9
Reputation: 9862
Simplest Way is :
string str = "iddaa///news/haber05112013.jpg";
str = str.Replace("///", "/").Replace("//","/");
Upvotes: 0
Reputation: 10456
This code will handle any length of /
sequence:
string a = //some string
while(a.Contains(@"//"))
{
a = a.Replace(@"//",@"/");
}
@dasblinkenlight answer is better. Regex is the right way to go.
Upvotes: 0