如何在C#.NET中用空字符替换字符串中的char [英] How to replace a char in string with an Empty character in C#.NET
本文介绍了如何在C#.NET中用空字符替换字符串中的char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的字符串:
I have a string like this:
string val = "123-12-1234";
如何在C#中使用空字符串替换破折号。
How can I replace the dashes using an empty string in C#.
我的意思是 val.Replace(char oldChar,newChar);
需要做什么进入 oldChar
和 newChar
。
推荐答案
您可以使用 Replace()
的不同重载,该重载采用字符串。
You can use a different overload of Replace()
that takes string.
val = val.Replace("-", string.Empty)
这篇关于如何在C#.NET中用空字符替换字符串中的char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文