在一个字符串替换反斜线 [英] Replacing backslash in a string

查看:147
本文介绍了在一个字符串替换反斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个问题想取代反斜线日期字符串在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆