用管道替换字符串中的所有反斜杠

用管道替换字符串中的所有反斜杠

问题描述:

我有字符串:\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, "|")