用C#替换所有的'\'字符为“/” [英] Replacing all the '\' chars to '/' with C#

查看:1250
本文介绍了用C#替换所有的'\'字符为“/”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能替换字符串转换成'/'用C#的所有'\'字符?
为例,我需要做@C:/ ABC / DEF从@C:\abc\def

How can I replace all the '\' chars in a string into '/' with C#? For example, I need to make @"c:/abc/def" from @"c:\abc\def".

推荐答案

借助更换的功能似乎适合:

string input = @"c:\abc\def";
string result = input.Replace(@"\", "/");

和小心一个常见的问题:

And be careful with a common gotcha:

由于字符串不变性在.NET这个函数不修改要调用它=字符串实例>它返回的结果。

Due to string immutability in .NET this function doesn't modify the string instance you are invoking it on => it returns the result.

这篇关于用C#替换所有的'\'字符为“/”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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