How do you remove Unit Separator (Unicode: 0x1f) from a string using javascript?
I have string that is creating xml however the Unit Separator character is making the XML invalid. Is there a way in JavaScript to strip out such a character?
I have tried this however it does not work:
input.replace('/\c_/g', '');
How do you remove Unit Separator (Unicode: 0x1f) from a string using javascript?
I have string that is creating xml however the Unit Separator character is making the XML invalid. Is there a way in JavaScript to strip out such a character?
I have tried this however it does not work:
input.replace('/\c_/g', '');
2 Answers
Reset to default 5This should work:
input = input.replace(RegExp(String.fromCharCode(31),"g"),"")
You can add a character whose unicode code you know in a javascript string literal using \xXX
.
This should work :
input = input.split("\0x1f").join('');