用管道替换字符串中的所有反斜杠 [英] Replace all backslashes in a string with a pipe
本文介绍了用管道替换字符串中的所有反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有字符串:\rnosapmdwq \salesforce \R3Q \ OutputFiles \Archive
I have the string: \rnosapmdwq\salesforce\R3Q\OutputFiles\Archive
当我尝试使用时,我收到一个无法识别的转义序列将其发送到.NET Web服务。
I'm getting a unrecognized escape sequence when I try to send this to a .NET web service.
我正在尝试将所有\替换为|将它发送到服务器。
I'm trying to replace all of the "\" with "|" to send it to the server.
我知道我可以使用替换方法,但只能替换第一个元素。我想我需要使用正则表达式来解决它。
I know I can use the replace method but that only replaces the first element. I think I need to use a regular expression to solve it.
这是我到目前为止所拥有的:
Here's what I have so far:
Path = Path.replace("\\/g", "|");
这是错误的。
推荐答案
你不需要将正则表达式作为一个字符串,它有助于在那里有第一个 /
You don't need to make a regex a string, and it helps having that first /
in there
Path = Path.replace(/\\/g, "|")
这篇关于用管道替换字符串中的所有反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文