The CreatorCon Call for Content is officially open! Get started here.

Need help with JavaScript String substr().

Annie10
Tera Contributor

Hello,

I have a string contains "abc\1234"

I would like to extract from the back slash and get the number only such as "1234"

Can someone please help?  Thank you

 

1 ACCEPTED SOLUTION

@Annie10  Please continue to use double back slashes, generally \ has a special meaning example: \n is for the next line and hence scripting languages doesn't allow you to type one single backslash and to cut the meaning of backslash you have to use double slashes. 

 

Conclusion is \\ is equivalent of \ in a string.

 

Please use the same line of code and it should work fine.

 

return source.u_name.slice(source.u_name.indexOf('\\')+1);

 

Thanks!!

View solution in original post

16 REPLIES 16

@Annie10 I believe you are trying to import data using import set, please see my excel sheet and the result using the same code

 

Excel sheet with the data:

Arun_S1_0-1686035684968.png

 

Transform Map (Field map updating the incident description):

Arun_S1_1-1686035763926.png

 

Updates on the incident:

Arun_S1_2-1686035803465.png

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.

 

Annie10
Tera Contributor

Thank you so much for continuing provide support.

Annie10
Tera Contributor

@Arun_S1 

 

What is +1 means?

Annie10_0-1686203769592.png

 

 

@Annie10 indexOf will return the position of the \ symbol, +1 is to instruct the system to pick up the string after the \ symbol.

Drisya Nair
Tera Contributor

Hello @Annie10 

Please try the below script.

 

var string = "abc\1234";
var newString  = string.match(/(\d+)/g)
gs.print(newString);
 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.