We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a lot of larger blocks of text for my recent project, and I wanted to use a .txt file and loadStrings() to store/use them. However, the apostrophes and quotation marks in the text won't display correctly. I tried adding the usual backslash, but then the backslash is just displayed next to the unloaded character. This has happened both when using println() and text(). Any suggestions?
Original text:
Plastic can’t be broken down by marine microorganisms, so while plastic debris gets smaller, it doesn’t go away. “Ocean confetti” has been found in every area and depth of the ocean, and we still don’t know much about its effects.
Code:
void setup() {
/*loading text into a string array (I have a lot, but only one has apostrophes and
quotation marks so I'll just use lines[4]*/
String[] lines = loadStrings("strings.txt");
//dislay text
println(lines[5]);
}
Output:
Output when I add backslashes in the .txt file:
Answers
You may replace() all
’
w/'
. And replace() all“
&”
w/"
. Like this:println( lines[5].replace('’', '\'').replace('“', '"').replace('”', '"') );
http://docs.Oracle.com/javase/8/docs/api/java/lang/String.html#replace-char-char-
Or choose another font for the PDE, which is capable to display such special Unicode chars. :-\"
Thank you! Totally fixed now.