Reputation: 900
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', '');
Upvotes: 3
Views: 4132
Reputation: 1605
This should work:
input = input.replace(RegExp(String.fromCharCode(31),"g"),"")
Upvotes: 5
Reputation: 382274
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('');
Upvotes: 1