我需要糾正字符串中不需要的字符。 不需要的字符:的 「i」的代替更正字符串中的字符?
「C」而不是「C」,「I」 「U」代替,而不是「G」 「○」「ü」 「G」代替「 ö「 」s「而不是」ş「
我已經寫了這個方法。但它不起作用。
public string UrlCorrection(string text)
{
text = (text.ToLower()).Trim();
var length = text.Length;
char chr;
string newtext="";
for (int i = 0; i < length; i++)
{
chr = text[i];
switch (chr)
{
case 'ç':
newtext = text.Replace("ç", "c");
break;
case 'ı':
newtext = text.Replace("ı", "i");
break;
case 'ü':
newtext = text.Replace("ü", "u");
break;
case 'ğ':
newtext = text.Replace("ğ", "g");
break;
case 'ö':
newtext = text.Replace("ö", "o");
break;
case 'ş':
newtext = text.Replace("ş", "s");
break;
default:
break;
}
}
newtext = text;
return text;
}
我該如何執行此任務?
它不會工作,因爲他會調用text.Replace每一次。只有最後一個匹配的字符會被替換。 – 2010-09-16 12:55:22
對。在寫答案之前沒有看過代碼。 – 2010-09-16 12:56:15
不是。這沒有解決我的問題。我不知道問題在哪裏。 – beratuslu 2010-09-16 12:56:21