Unable to replace backward slash "\" from a string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2018 04:12 PM
Hi All,
I am trying to split/replace a string that has backward slash"\" but unable to get the desired result.
var strVal = "Au\Group\This group"
var newStr = strVal.replace(/\\/g,"/"); [ or var newStr = strVal.split("\'");]
gs.info(newStr)
**Script completed in scope : AuGroupThis group
Is there any other way to achieve this. Any advise/inputs will be of great help.
Thank you.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2018 12:29 PM
I find the code but try this way and see:
// Replace any '\' in str1 with '/' and store the result in str2 re2 = new RegExp("\\\\","g"); str2 = str1.replace(re2,"/");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2018 03:42 PM
I have tried this and it does not work. It returns a single string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2018 02:01 PM
strVal.split("\\");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2018 03:45 PM
Hi Greg,
I see that the solution works if there are double backslashes, but i cant make any changes to the input string to have double backslash .
so is there no other way to remove a singe instance of backslash?
Thank you,