actionscript 3 - how to get the html text length without set it to a textfield? -
in actionscript ,i didn't find direct way string's length of html text.here's how things work
var mytext:string = "<p>this <b>some</b> content <i>render</i> <u>html</u> text.</p>"; mytextbox.htmltext = mytext; trace(mytextbox.length);
deal large content of html text performance problem.
is there way can length while don't have pass text device?
i see 2 ways extract text xml:
- for
xhtml
best way parse xml , extract text nodes for types of text can try
regexp
matches text not part of html tag (http://regexr.com?363li)var s:string = "<p>this <b>some</b> content <i>render</i> <u>html</u> text.</p>"; //by textfield var tf:textfield = new textfield(); tf.htmltext = s; trace(tf.text); trace(tf.length); //well-formed xml xml.ignorewhitespace = false; var x:xml = new xml(s); var t:string = ""; var list:xmllist = x..*; each(var node:xml in list) if(node.nodekind() == "text") t += node; trace(t); trace(t.length); //by regexp (non wel formed xml) var match:array = s.match(/(?<=^|>)[^><]+?(?=<|$)/gs); s = match.join(""); trace(t); trace(t.length);
output:
22528 21 ms 22528 35 ms 22528 20 ms
but these techniques seems equals performance, can see string 22k chars methods runs same result 20-30 ms, anyway can try both methods input.
Comments
Post a Comment