我需要纠正字符串中不需要的字符.不需要的人物
"c"而不是"ç""i"而不是"ı""u"而不是"ü""g"而不是"ğ""o"而不是"ö""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;
}
Run Code Online (Sandbox Code Playgroud)
我如何实现此任务?
基本上你可以这样做:
newtext = text.Replace("ç", "c");
newtext = newtext.Replace("?", "i");
newtext = newtext.Replace("ü", "u");
newtext = newtext.Replace("?", "g");
newtext = newtext.Replace("ö", "o");
newtext = newtext.Replace("?", "s");
Run Code Online (Sandbox Code Playgroud)
无需开关/外壳/索引疯狂.
| 归档时间: |
|
| 查看次数: |
964 次 |
| 最近记录: |