本文介绍了如何用斜线“/"替换反斜线“\"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的代码中,我想用字符串中的正斜杠字符 / 替换反斜杠字符 \.我试过以下代码:
In my code I want to replace backslash character \ by a forward slash character / in a string. I've tried the following code:
string str = chosen_file.Replace("/", @"\");其中,chosen_file 是一个 string,其中包含多次出现的 \ 字符.但它似乎不起作用.
where, chosen_file is a string which contains numerous occurances of the \ character. But it doesn't seem to be working.
我可以知道针对此问题的任何其他解决方案吗?
Can I know any other solutions for this issue?
推荐答案如果看String.Replace的定义:
If you look at the definition of String.Replace:
public string Replace( string oldValue, string newValue )和您的电话:
chosen_file.Replace("/", @"\");您正在用反斜杠替换正斜杠.如果您交换参数,您应该会获得所需的行为.
You are replacing forward slashses with backslashes. If you swap the arguments you should be getting the desired behavior.
更多推荐
如何用斜线“/"替换反斜线“\"?
发布评论