Some useful String functions that van be used in ActionScript 3.0 projects …
Strip Spaces from a String
private function stripSpaces
($myString
:String):String
{
return $myString
.split(" ").join("");
}
Get the Last Char in a String
private function getLastCharInString
($s
:String):String
{
return $s
.substr($s
.length
-1,$s
.length);
}
Email Validation
private function isValidEmail
($email
:String):Boolean {
var emailExpression
:RegExp =
/([a-z0-9._-]+?)@([a-z0-9.-]+)\.([a-z]{2,4})/;
return emailExpression
.test($email
);
}
Number of bytes in a UTF8 String
private function getNumBytesUTF8
($s
:String):Number {
var byteArray
:ByteArray =
new ByteArray();
byteArray
.writeUTFBytes($s
);
return byteArray
.length;
}
Capitalise the First Letter of a String
function catipaliseFirstLetter
($s
:String):String {
return $s
.substring(0, 1).toUpperCase() + $s
.substr(1, $s
.length
-1);
}
Capitalise a String
function catipaliseString
($s
:String):String {
return $s
.toUpperCase();
}
Strip http:// or https://
function stripHttp
($string
:String, $stripWWW
:Boolean =
true):String
{
var regexp
:RegExp =
new RegExp(!$stripWWW
? "https*:\/\/" : "https*:\/\/(www\.)*", "ig");
return $string
.replace(regexp
, "");
}
About the Author

Daan is a Creative-Geek with passion for Adobe Flash , Flex and Air. He loves learning and sharing new techniques! Follow him on
Twitter to keep up to date with the Creative-Geeks blog and other subjects. Contact him on e-mail : info[at]creative-geeks.com
You know what would be great… extracting the #hashtags @user or http://url from a twitter message, ex:
In Item Renderer:
override public function set data (o:Object):void {
trace(‘New Tweet: ‘ + o);
var original:String = o.title;
_tweet = original.replace(/(^|\s)@(\w+)/g, “$1@$2“);
_final = _tweet.replace(/(^|\s)#(\w+)/g, “$1#$2“);
ta.htmlText = _final;
}
Sorry, but I’m using this page also for my personal reference :p
Hi Joseph, thanks for the contribution …
It’s also a usefull String function within AS3 so I like it