How to split using backslash (\)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2020 04:12 AM
Hi All,
I want to split the string using a backslash (\) and i need value after the backslash (\)
but I am not getting proper output
Expected output == "_DJ_Ima_KPI-Rap"
var group = "GROUP\_DJ_Ima_KPI-Rap";
var n = group.split("\");
gs.log(n[0]);
gs.log(n[1]);
The expected output is :
GROUP
_DJ_Ima_KPI-Rap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2020 04:18 AM
Hi,
this should work
during testing you should escape the slash with 1 more slash character so that it is recognised
var group = "GROUP\\_DJ_Ima_KPI-Rap";
gs.info(group);
var n = group.split("\\");
gs.info(n.length);
gs.info(n[0]);
gs.info(n[1]);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2020 04:21 AM
Hi Ankur,
This is hard coded value it should be with single \ only "GROUP\_DJ_Ima_KPI-Rap";
help me with single slash \
Thanks
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2020 04:25 AM
Hi Ramesh,
it won't work with hard-coded value in background script since the string should recognize the slash character so in order for that to work you need to escape that character
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2020 04:18 AM
"\" is used to escape characters. Is the group value a hard coded string like above? Or is it a variable?
If so you can use:
var n = group.split("\\")
If it is hard coded use this:
var group = "GROUP\\_DJ_Ima_KPI-Rap";
var n = group.split("\\");
gs.print(n[0]);
gs.print(n[1]);