From 0ed50738a9afd88a68a892dd26c6fdbd9ae88bb7 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 7 Sep 2006 21:30:11 +0000 Subject: [PATCH] Added append() and prepend(). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4359 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/StringUtil.as | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/as/com/threerings/util/StringUtil.as b/src/as/com/threerings/util/StringUtil.as index e035d26dd..96ef27b66 100644 --- a/src/as/com/threerings/util/StringUtil.as +++ b/src/as/com/threerings/util/StringUtil.as @@ -43,6 +43,32 @@ public class StringUtil return (str.lastIndexOf(substr, 0) == 0); } + /** + * Append 0 or more copies of the padChar String to the input String + * until it is at least the specified length. + */ + public static function pad ( + str :String, length :int, padChar :String = " ") :String + { + while (str.length < length) { + str += padChar; + } + return str; + } + + /** + * Prepend 0 or more copies of the padChar String to the input String + * until it is at least the specified length. + */ + public static function prepad ( + str :String, length :int, padChar :String = " ") :String + { + while (str.length < length) { + str = padChar + str; + } + return str; + } + /** * Utility function that strips whitespace from the ends of a String. */