Talk:StringUtil

From Unify Community Wiki
Jump to: navigation, search

The word wrap function is a bit verbose. Usually code scanning strings character by character is a sign that one could find system library functionality to do it with less code. Here's an example that uses a regular expression to do the hard work for you. (Untested btw.)

<javascript> import System.Text.RegularExpressions;

static function Wrap(str : String, lineLength : int) : String { if (str.Length <= lineLength) return str;

       var regex = String.Format("(.{1}1,{2}{3})(\\s+|$)\\n?|(.{1}{2}{3})", "{", lineLength, "}");

return Regex.Replace(str, regex, "$1$3\n"); } </javascript> --KeliHlodversson 06:22, 29 March 2007 (PDT)

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox