0

I need to format a string removing the control characters before creating it as an xml. The texts are both in English and French. For eg in words like d?une, I wanted to remove "?" from the text. I tried \p{Cntrl}, [\u0000-\u001f], /[^a-zA-ZÀ-ÿ]/ none of them worked. Could anyone suggest a solution thanks in advance

DJ4186
  • 159
  • 1
  • 3
  • 16
  • 2
    Did you really intend to type question marks in the text of this question, or were you trying to type a control character directly? – VGR Nov 30 '17 at 22:47

1 Answers1

0

This will search and replace all non ASCII letters:

String resultString = subjectString.replaceAll("[^\\x00-\\x7F]", "");

Courtesy of FailedDev -> Replace non ASCII character from string.

Cardinal System
  • 2,749
  • 3
  • 21
  • 42
  • Thanks for the suggestion but this will not work in texts like "Isolant de polystyr�ne extrud� rig" where I want to strip of control characters like this.. Do you have any other suggestion ? – DJ4186 Dec 01 '17 at 16:03
  • 1
    @JavaLearner What do you mean by 'control characters'? – Cardinal System Dec 01 '17 at 22:37