在一个字符串替换反斜线 [英] Replacing backslash in a string
问题描述
我有几个问题想取代反斜线日期字符串在C#.NET。
I am having a few problems with trying to replace backslashes in a date string on C# .net.
到目前为止,我使用的:
So far I am using:
string.Replace(@"\","-")
但它未完成更换。任何人都可以请帮助?
but it hasnt done the replacement. Could anyone please help?
推荐答案
与string.replace
不修改字符串本身,而是返回一个新字符串,其中最有可能你是扔掉。做到这一点,而不是:
string.Replace
does not modify the string itself but returns a new string, which most likely you are throwing away. Do this instead:
myString= myString.Replace(@"\","-");
在一个侧面说明,这种操作通常出现在code表示手动渣土周围的格式化日期字符串。在大多数情况下有更好的方式做你想要的(这是?)不是这样的事情。
On a side note, this kind of operation is usually seen in code that manually mucks around with formatted date strings. Most of the time there is a better way to do what you want (which is?) than things like this.
这篇关于在一个字符串替换反斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!