Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to split using backslash (\)

ramesh_r
Giga Sage

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
10 REPLIES 10

Not applicable

Hi,

How to separate incoming value dynamically here(like incoming value will be of the form sourceValue(domain\username or might be only username)) and i need to extract only username here.

Note:-incoming value will be type "domain\username username" only

var str = "domain\username ";//i'll be assigning with "domain\username "= sourceValue which is dynamic
var n=str.split("\\");
var domain= n[0]; //It is the 1st element
var userName= n[1]; //it is the 2nd element in the array

if(userName!=null)
{
gs.log(userName);
}
else
{
gs.log(domain);
}

 

I'm using this code and getting domainusername as output .expected was only username

 

How to solve this to get only username?