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:

  1. for xhtml best way parse xml , extract text nodes
  2. 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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -