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:22 AM
Hi Willem,
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:39 AM
It will not accept "GROUP\_DJ_Ima_KPI-Rap" as a hardcoded string. If you retrieve it dynamically you can use:
Where groupname_field is for example a name field.
group = decodeURIComponent(groupname_field);
var n = group.indexOf("_");
gs.info(group.substr(0, n));
gs.info(group.substr(n));
Or if you want to hard code it, do it like this:
group = decodeURIComponent("GROUP\_DJ_Ima_KPI-Rap");
var n = group.indexOf("_");
gs.info(group.substr(0, n));
gs.info(group.substr(n));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2020 04:19 AM
Hello Ramesh,
Try this,
var str = 'first\\last';//returns 'first\last'
var arr = str.split('\\');
gs.log(arr[1]);//returns last
Thanks,
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2020 08:00 AM
Hope you are doing well.
Is your question resolved? Or do we need to follow-up on this?
Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.
Kind regards,
Willem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2020 09:28 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark my answer as correct & helpful to close the thread.
If not, please let us know if you need some more assistance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader