How to remove special character (:\) from string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 06:47 AM
Hi All,
Need a script to remove special character specially ":\" from string. Due to this special characters my API is not working.
I have tried below scripts but not working please suggest.
var str = "F:\";
var test = str.replace(/[^\d\w]/gi, '');
gs.print("Str: " + str + "\ntest: " + test);
---------------------------------------------------------------------
var str = "F:\";
var test = str.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');
gs.print("Str: " + str + "\ntest: " + test);
Thanks in Advance..
Vinayak
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 09:36 PM
Hi Chuck,
I have tested this but unfortunately not working. my code is as below. correct if i missed anything.
var str = "F:\";
var v1 = str.replace(':', '');
var v2 = v1.replace('\\', '');
gs.info("Str: " + str + "\nreplaced str: " + v2);
Thanks,
Vinayak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2020 06:10 AM
The issue with this script is on line 1. The JavaScript interpreter is reading it as an unterminated string because \" is actually making the quote character part of the string, not a terminator.
You can change it to either of these two:
var str = "F:\\"; // creates F:\
var str = "F:\""; // creates F:"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2023 04:40 AM - edited 04-06-2023 04:41 AM
Hi, Im trying to remove special characters from description on RITM level, after copied all variables to description (BR):
(function executeRule(current, previous /*null when async*/) {
var desc = current.variables.u_description;
current.description = 'Request Item : ' + current.cat_item.getDisplayValue() + '\nRequest Number: ' + '\n' + current.number + '\nRequest Type: ' + current.variables.request_type.getDisplayValue() +'\nShort Description: ' + current.variables.u_short_description + '\nDescription: ' + desc + '\nJustification: ' + current.variables.justification + '\nCost Approval: ' + current.variables.cost_approval.getDisplayValue();
})(current, previous);
so far didn't manage to succeed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 07:17 AM
Hi
Your str variable declaration at the first line with the initial value "F:\" wouldn't work, because it's not a proper string literal. It has to be escaped with "\" to be able to apply any function to it.
So, if you'd try the below snippet, that should give you the desired result. You can use the global replace link below to replace it everywhere in the string:
var str = "F:\\";
var test = str.replace(/:\\/g, '');
gs.info("Str: " + str + "\nreplaced str: " + test);
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 09:34 PM
Hi Rishabh,
your code is working but there is only one blackslash in my string.