Im current开发者_如何学运维ly loading some text through XML via my doc class - this text contains \n tags
XML example:
What im looking to do is replace \n in my string with
I've tried a few things:
string = string.split("\n").join('<br/>');
and
string = string.replace("\n","<br/>");
However tracing out string afterwards, or just seeing what myTextField.htmlText = string; displays, I still see the \n tags
Any ideas?
Code illustrated:
// The string which contains the XML loaded content
var string:String;
var myTextField:TextField = new TextField();
myTextField.defaultTextFormat = myFormat;
myTextField.width = 300;
myTextField.border = false;
myTextField.embedFonts = true;
myTextField.multiline = true;
myTextField.wordWrap = true;
myTextField.selectable = false;
myTextField.htmlText = string;
addChild(myTextField);
You want:
string = string.replace(/\n/g, "<br>");
This will replace all newlines with <br>
.
I believe you want:
str = str.replace("\\n", "\n");
OR the following applies to all instances:
str = str.split("\\n").join("\n");
Try that
The solution above didnt work for me
string = string.replace(/\n/g, "<br>");
I was able to do the same thing this way
string = string.replace(new RegExp(String.fromCharCode(13), "<br>");
im using flash cs6-as3
hopefully this helps if the other doesnt work for you
精彩评论