string replace \ n或<br/> with  在as3

时间:2009-09-14 11:05:37

标签: flash actionscript-3

我在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/>但我在换行符之间有不需要的空格,所以现在我使用了&#xD;对于linebreak,这工作正常,所以我需要替换这个&#xD;)字符,其中\n存在..我试过

TFhtmlText = TFhtmlText.split('\n').join('&#xD;')
 txtField.htmlText = TFhtmlText;


TFhtmlText=TFhtmlText.replace(/\n/g, "&#xD;");

但不工作......我怎样才能实现呢

提前致谢

3 个答案:

答案 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('&#xD;');
txtField.htmlText = my_str;

答案 2 :(得分:0)

没有理由说它不起作用。

tfHtmlText = tfHtmlText.split(' \n ').join('&#xD;')
txtField.htmlText = tfHtmlText;

或者,如果你想放<br />那么

tfHtmlText = tfHtmlText.split(' \n ').join('<br />')
txtField.htmlText = tfHtmlText;

请注意\n

参数中split()之前和之后的空格