我在as3中有TextField,因为我指定了像
这样的html值var TFhtmlText:String = "<span class='Header'>The value need to be 25 percentage \n and percentage be 50 percent.</span>"
txtField.htmlText = TFhtmlText;
从上面我需要换行25个百分比,因为我使用<br/>
但我在换行符之间有不需要的空格,所以现在我使用了
;对于linebreak,这工作正常,所以我需要替换这个
)字符,其中\n
存在..我试过
TFhtmlText = TFhtmlText.split('\n').join('
')
txtField.htmlText = TFhtmlText;
TFhtmlText=TFhtmlText.replace(/\n/g, "
");
但不工作......我怎样才能实现呢
提前致谢
答案 0 :(得分:0)
下次请正确格式化代码,难以阅读。
假设我正确读取它,您想要按如下方式编写字符串。将\ n替换为\ n并删除周围的空白区域。
var TFhtmlText:String = "The value need to be 25 percentage<br/>and percentage be 50 percent."
txtField.htmlText = TFhtmlText;
答案 1 :(得分:0)
这个怎么样:
var my_str:String = new String(TFhtmlText);
my_str = my_str.split('\n').join('
');
txtField.htmlText = my_str;
答案 2 :(得分:0)
没有理由说它不起作用。
tfHtmlText = tfHtmlText.split(' \n ').join('
')
txtField.htmlText = tfHtmlText;
或者,如果你想放<br />
那么
tfHtmlText = tfHtmlText.split(' \n ').join('<br />')
txtField.htmlText = tfHtmlText;
请注意\n
split()
之前和之后的空格