mmkd
mmkd

Reputation: 900

JavaScript - Remove Unit Separator (Unicode: 0x1f) Character From String

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

Answers (2)

lmortenson
lmortenson

Reputation: 1605

This should work:

input = input.replace(RegExp(String.fromCharCode(31),"g"),"")

Upvotes: 5

Denys Séguret
Denys Séguret

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

Related Questions