We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › removing non-printing characters
Page Index Toggle Pages: 1
removing non-printing characters? (Read 191 times)
removing non-printing characters?
Mar 3rd, 2009, 6:04pm
 
I'm trying to read a two-column file that will be plotted as a series of points, but there seem to be some hidden characters stuck in there. I'm using trim to strip whitespace and splitTokens to separate the columns, but when I print the resulting array to the text area, the numbers come up like this: ?42. What do the question marks represent and how do I get rid of them?
Re: removing non-printing characters?
Reply #1 - Mar 3rd, 2009, 9:41pm
 
They might be control chars (?) or Unicode chars not present in the font used to display the string.
Actually, they are not control chars, they are displayed as squares.
You can use a regular expression to get rid of them:
Code:
String toClean = "ab\bcd\fe\uA600fg\u1604hi\u3636jkl";
println(toClean);
String cleaned = toClean.replaceAll("[\u0100-\uFFFF]+", "");
println(cleaned);
Re: removing non-printing characters?
Reply #2 - Mar 5th, 2009, 8:39pm
 
Thanks for the tip, makes sense.
Page Index Toggle Pages: 1