Replace / with \ in processflow?

 3 Replies
 3 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
PBL
Basic Member Send Private Message
Posts: 9
Basic Member

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 Send Private Message
Posts: 1127
Veteran Member
To have JavaScript recognize special characters you need to prefix them with \ - so str.replace/\//g,"\") should work.
David Williams
LeslieG
Veteran Member Send Private Message
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 Send Private Message
Posts: 9
Basic Member
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,"\\")