0

So I have a database string which is <@$244230034359844866> <@$244230033359844566>. How would I make it so that when I do console.log it only shows up with 244230034359844866, 244230033359844566 Thanks

1

As mentioned by @Sagar you can create string list and then simply use replaceAll('\D','') to get only numbers from string.

var myStringArray = ["<@$244230034359844866>","<@$244230034359844868>"];
var arrayLength = myStringArray.length; 
for (var i = 0; i < arrayLength; i++) { 
 system.debug(myStringArray[i].replaceAll('\\D',''));
}
0

@NotAndy, you can put the string into a list and then iterate over it to fetch the number using subString function of string. I am assuming that the string format will always be same as you mentioned above. Please find the code below for your reference-

var myStringArray = ["<@$244230034359844866>","<@$244230034359844868>"];
var arrayLength = myStringArray.length; 
for (var i = 0; i < arrayLength; i++) { 
   console.log(myStringArray[i].substring(3, 21));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.