如何用斜线“/"替换反斜线“\"?

编程入门 行业动态 更新时间:2024-10-14 16:23:29
本文介绍了如何用斜线“/"替换反斜线“\"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的代码中,我想用字符串中的正斜杠字符 / 替换反斜杠字符 \.我试过以下代码:

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.

更多推荐

如何用斜线“/"替换反斜线“\"?

本文发布于:2023-11-06 08:13:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563160.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜线   如何用   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!