用正斜杠替换所有黑斜杠 [英] Replace all blackslashes with forward slash

查看:25
本文介绍了用正斜杠替换所有黑斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

替换所有出现的"的最佳方法是什么?用/";在 c# 中的字符串中?

What is the best way to replace all occurrences of "" with "/" in a string in c#?

我尝试了以下选项,但都不起作用.

I've tried the following options but neither work.

  • variable.Replace("", "/");
  • variable.Replace(@"", @"/");

推荐答案

你应该分配替换结果:

var res = variable. Replace("\", "/"); //  you need "\" because "" is escape symbol.

var res = variable.Replace(@"", "/"); 

这篇关于用正斜杠替换所有黑斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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