我有这个问题,其中有一些strnig,除了其他东西之外的文字表达式"\\",我想替换它"\",当我尝试用string.replace替换它时,只重复第一次出现,如果我这样做使用正则表达式它根本不替换它
我在线检查了一些RegEx测试人员,据说我的代码没问题,返回我的意思,但我的代码根本不起作用
同 string.replace
example = "\\\\url.com\\place\\anotherplace\\extraplace\\";
example = example.replace("\\\\","\\");
returns example == "\\url.com\\place\\anotherplace\\extraplace\\";
Run Code Online (Sandbox Code Playgroud)
使用RegEx
example = Regex.Replace(example,"\\\\","\\");
returns example = "\\\\url.com\\place\\anotherplace\\extraplace\\";
Run Code Online (Sandbox Code Playgroud)
如果我使用文字是相同的情况(在替换函数参数上使用(@"\\", @"\")给出与上面相同的结果).
谢谢!
编辑:
我认为我的最终目标是令人困惑所以我会在这里更新它,我想要做的是:
输入:
保存字符串的变量:"\\\\url.com\\place\\anotherplace\\extraplace\\"
处理
保存字符串的输出变量"\\url.com\place\anotherplace\extraplace\"
(因此我可以将其发送到ffmpeg并将其识别为有效路径)
改变这个:
example = "\\\\url.com\\place\\anotherplace\\extraplace\\";
Run Code Online (Sandbox Code Playgroud)
对此
example = @"\\\\url.com\\place\\anotherplace\\extraplace\\";
Run Code Online (Sandbox Code Playgroud)
这不是Regex.Replace参数问题.
| 归档时间: |
|
| 查看次数: |
144 次 |
| 最近记录: |