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
Tera Contributor

Hello,

Can someone please help?  I have data coming from an excel file that contains column with user name: 'abc/T1230"

 

I need help with Transform Map script to extract just the numbers from the user name.  I have tried the following, but it did not work.  Many thanks to you

 

return source.u_name.toString().replace(/(\d+)/g, "");

wndydngy
Tera Expert

Hi,

 

You can try using the split method. Basically what it does is split your string into an array of substrings. Try this code:

 

var str = "abc\1234";
var myArray = str.split('\');

 

The string will be split into two substrings:

myArray [0] = 'abc'

myArray [1] = '1234'

 

Please mark helpful if correct, thanks!