If I explicitly set the text of a showMsgBox prompt to something like:
prompt:"This is line one\nThis is line two"
it works. If I use text retrieved from an XML file that looks like this:
<promptText><![CDATA[This is line1\nThis is line 2]]></promptText>
or even this:
<promptText>This is line1\nThis is line 2</promptText>
the newline characters aren't translated appropriately. I've tried the following:
var tmpString:String=String(promptText); // also, promptText.toString();
but with the same results.
Any idea what I'm doing wrong? Thanks!
You need to read String Literals vs. String Values. Basically the \ is only treated as a special character when it appears in quotes in code. When you're reading from a file, getting use input, etc. then a \ is just another character.
Ok. I'd also tried "\\n," too, but with no results. I'm guessing for the same reasons?
Is there anyway to get \n recognized as newlines when they're part of a predefined string? I apologize for my dense-ness!
Edit: All right, so maybe it's not the best way, but the following worked:
FYI :) (I'm sure such an approach could potentially lead to other problems, but it works for me for now! ;) )
If s is loaded from a file then you can just replace \\n with \n like this to get what you want...
s = s.split("\\n").join("\n");