如何从字符串中删除一些字符 [英] how to remove some character from string
本文介绍了如何从字符串中删除一些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。
我想删除所有特殊字符或所有其他字符,但我不想删除像@ /:= etc和alpha bates。
最好的方法是什么
string mystring =?♫┘〜.┘&╤+ @ \ ??? ?v?* =?\ n?E ??? M ??? u ????????????????????????????????????解决方案
请尝试以下链接
替换c#中的特殊字符 [ ^ ]
http://stackoverflow.com/questions/21388090/how-to-replace -all-special-character-a-string-using-c-sharp [ ^ ]
< ; br />
< br />
< br />
< pre lang =cs>< br />
string mystring =?♫♠〜.┘&╤+ @ \\ \\ ???? v'* =?\\\
的ΔE??? M ????????????????????????????????????????????????????????????? b $ b char [] allowCharacter = new char [] {'','@','\ n','\ r','。',':','[',']','/ , '*', ';', '=', ' - ', '', '', '+', '
', '','〜?! ',''','^','&','(',')','_',' - ','>','<','!','`',' {','}','|'};< br />
foreach(mystring中的char项)< br />
{< br />
if(allowCharacter .Contains(item)|| char.IsLetter(item)|| char.IsNumber(item))< br />
{< br />
test = test + item.ToString() ;< br />
< br />
}< br />
< br />
else< br />
{< br />
test = test +。;< br />
}< br />
}< / pre>< br />
Hello all.
i want to remove all special character or all other character but i do not want to remove like @ / : = etc and alpha bates.
what is the best way to do it
string mystring="♫♠~.┘&╤+@\????v?*=?\n?E???M???u??????r[?????o?W,~ ?:";
解决方案
Please try the below links
replace special characters in c#[^]
http://stackoverflow.com/questions/21388090/how-to-replace-all-special-character-into-a-string-using-c-sharp[^]
<br /> <br /> <br /> <pre lang="cs"><br /> string mystring="♫♠~.┘&╤+@\????v?*=?\n?E???M???u??????r[?????o?W,~ ?:";<br /> string test="";<br /> char[] allowCharacter = new char[] {' ','@','\n','\r','.',':','[',']','/','*',';','=','-','"','?','+','
','!','~','#','^','&','(',')','_','-','>','<','!','`', '{','}','|'};<br /> foreach (char item in mystring)<br /> {<br /> if (allowCharacter.Contains(item) || char.IsLetter(item) || char.IsNumber(item))<br /> {<br /> test = test + item.ToString();<br /> <br /> }<br /> <br /> else<br /> {<br /> test = test + ".";<br /> }<br /> }</pre><br />
这篇关于如何从字符串中删除一些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文