Replace / with \ in processflow?

 3 Replies
 3 Subscribed to this topic
 51 Subscribed to this forum
Sort:
Author
Messages
PBL
Basic Member
Posts: 9
Basic Member
New Poster
New Poster
Congrats on posting!
Engaged Reader
Engaged Reader
You are an engaged reader!
Avid Reader
Avid Reader
Avid Reader art thou!

I am retrieving the PRTFILEPATH field from the USERRPT table.  The field value looks like:

E:\lsfprod\law/print/userid/po120abc/1

It has a combination of \ and /.  When I use the value in a command, the syntax comes back as invalid.  

I am trying to use the javascript .replace method.  It replaces any character I specify - except /.  

Can someone tell me the correct syntax for the following (assuming where p is specified it should be / and where X is specified it should be \)?:

var str = RtvUSERRPT_PRTFILEPATH;
var res = str.replace(/p/g, "X");

 

Thank you

David Williams
Veteran Member
Posts: 1127
Veteran Member
New Poster
New Poster
Congrats on posting!
To have JavaScript recognize special characters you need to prefix them with \ - so str.replace/\//g,"\") should work.
David Williams
The.Sam.Groves
Veteran Member
Posts: 89
Veteran Member
"string".replace(/\//g, 'ForwardSlash');

Forward and backslashes have specific meanings in HTML and Javascript. To use them literally you need to escape them.
PBL
Basic Member
Posts: 9
Basic Member
New Poster
New Poster
Congrats on posting!
Engaged Reader
Engaged Reader
You are an engaged reader!
Avid Reader
Avid Reader
Avid Reader art thou!
Thank you so much for the speedy replies!. This is what worked (I needed the double \\ within the quotes as well as the escape character):

str.replace(/\//g,"\\")