if someone could give me the correct replace for :
|TEST_1608224413246_Jean_Lol|
replace both |
with nothing
I have already tested messagenew.replace("|", "");
but it only replace the first |
if someone could give me the correct replace for :
|TEST_1608224413246_Jean_Lol|
replace both |
with nothing
I have already tested messagenew.replace("|", "");
but it only replace the first |
// define let to store the test string
let s = '|TEST_1608224413246_Jean_Lol|'
// use string.replace to use regex to find and replace the | character
// | is a special character in regex so we must use \| to escape it
// using g to globally replace this means find all
// second parameter is what to replace it with empty string
s = s.replace(/\|/g, '')
// log the result as this is a demo
console.log(s)
// define let to store the test string
let s = '|TEST_1608224413246_Jean_Lol|'
// use string.replaceAll to find and replace the | character
s = s.replaceAll('|', '')
// log the result as this is a demo
console.log(s)
This would replace any and all |
not just 2, if specific number 2 is important here the regex could be updated to locate the beginning and end of string and replace them only from there.