字符串将 \n 替换为
>不工作
我目前通过我的文档类通过 XML 加载一些文本 - 该文本包含 \n 标签
XML 示例:
我想做的是将字符串中的 \n 替换为
我尝试了一些方法:
string = string.split("\n").join('<br/>');
以及
string = string.replace("\n","<br/>");
之后追踪 string ,或者只是看看 < em>myTextField.htmlText = string; 显示,我仍然看到 \n 标签
有什么想法吗?
代码如图:
// 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);
Im currently 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您想要:
这将用
替换所有换行符。You want:
This will replace all newlines with
<br>
.我相信您想要:
或者以下内容适用于所有实例:
尝试一下
I believe you want:
OR the following applies to all instances:
Try that
上面的解决方案对我不起作用
我可以用这种方式做同样的事情
我正在使用 flash cs6-as3
希望这会有所帮助(如果另一个不适合您)
The solution above didnt work for me
I was able to do the same thing this way
im using flash cs6-as3
hopefully this helps if the other doesnt work for you