3

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', '');

0

2 Answers 2

5

This should work:

input = input.replace(RegExp(String.fromCharCode(31),"g"),"")
Sign up to request clarification or add additional context in comments.

2 Comments

You're missing a new and a second argument to replace.
You are correct, although it doesn't look like I need the new, at least on Chrome
1

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('');

1 Comment

It should be "\x1f", leave the zero

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.