2022年ActionScript字符串操作[参 .pdf
《2022年ActionScript字符串操作[参 .pdf》由会员分享,可在线阅读,更多相关《2022年ActionScript字符串操作[参 .pdf(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 package com.xlands.utils import flash.utils.ByteArray; /* *字符串工具 * */ public class StringUtil /忽略大小字母比较字符是否相等; public static function equalsIgnoreCase(char1:String, char2:String):Boolean return char1.toLowerCase() = char2.toLowerCase(); /比较字符是否相等 ; public static function equals(char1:String, char2:
2、String):Boolean return char1 = char2; /是否为 Email 地址; public static function isEmail(char:String):Boolean if (char = null) return false; char=trim(char); var pattern:RegExp=/(w|_.-)+(w|-)+.)+w2,4+/; var result:Object=pattern.exec(char); if (result = null) return false; return true; 名师资料总结 - - -精品资料欢迎
3、下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 21 页 - - - - - - - - - /是否是数值字符串 ; public static function isNumber(char:String):Boolean if (char = null) return false; return !isNaN(parseInt(char) /是否为 Double 型数据 ; public static function isDouble(char:String):Boolean char=trim(cha
4、r); var pattern:RegExp=/-+?d+(.d+)?$/; var result:Object=pattern.exec(char); if (result = null) return false; return true; /Integer; public static function isInteger(char:String):Boolean if (char = null) return false; char=trim(char); var pattern:RegExp=/-+?d+$/; var result:Object=pattern.exec(char)
5、; if (result = null) return false; return true; /English; public static function isEnglish(char:String):Boolean if (char = null) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 21 页 - - - - - - - - - return false; char=trim(char); var pattern:RegExp=/A-Za-z+$/;
6、var result:Object=pattern.exec(char); if (result = null) return false; return true; /中文; public static function isChinese(char:String):Boolean if (char = null) return false; char=trim(char); var pattern:RegExp=/u0391-uFFE5+$/; var result:Object=pattern.exec(char); if (result = null) return false; re
7、turn true; /双字节 public static function isDoubleChar(char:String):Boolean if (char = null) return false; char=trim(char); var pattern:RegExp=/x00-xff+$/; var result:Object=pattern.exec(char); if (result = null) return false; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - -
8、- 第 3 页,共 21 页 - - - - - - - - - return true; /含有中文字符 public static function hasChineseChar(char:String):Boolean if (char = null) return false; char=trim(char); var pattern:RegExp=/x00-xff/; var result:Object=pattern.exec(char); if (result = null) return false; return true; /注册字符 ; public static fun
9、ction hasAccountChar(char:String, len:uint=15):Boolean if (char = null) return false; if (len 10) len=15; char=trim(char); var pattern:RegExp=new RegExp(a-zA-Z0-9a-zA-Z0-9_-0, + len + $, ); var result:Object=pattern.exec(char); if (result = null) return false; return true; 名师资料总结 - - -精品资料欢迎下载 - - -
10、 - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 21 页 - - - - - - - - - /URL地址; public static function isURL(char:String):Boolean if (char = null) return false; char=trim(char).toLowerCase(); var pattern:RegExp=/http:/A-Za-z0-9+.A-Za-z0-9+/=?%-&_:+!*()*$/; var result:Object=pattern.exec(c
11、har); if (result = null) return false; return true; / 是否为空白 ; public static function isWhitespace(char:String):Boolean switch(char) case : case t: case r: case n: case f: return true; default: return false; /去左右空格 ; public static function trim(char:String):String if (char = null) return null; return
12、 rtrim(ltrim(char); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 21 页 - - - - - - - - - /去左空格 ; public static function ltrim(char:String):String if (char = null) return null; var pattern:RegExp=/s*/; return char.replace(pattern, ); /去右空格 ; public static funct
13、ion rtrim(char:String):String if (char = null) return null; var pattern:RegExp=/s*$/; return char.replace(pattern, ); /是否为前缀字符串 ; public static function beginsWith(char:String, prefix:String):Boolean return (prefix = char.substring(0, prefix.length); /是否为后缀字符串 ; public static function endsWith(char:
14、String, suffix:String):Boolean return (suffix = char.substring(char.length - suffix.length); /去除指定字符串 ; public static function remove(char:String, remove:String):String return replace(char, remove, ); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 21 页 - - - -
15、- - - - - /字符串替换 ; public static function replace(char:String, replace:String, replaceWith:String):String return char.split(replace).join(replaceWith); /utf16转 utf8 编码; public static function utf16to8(char:String):String var out:Array=new Array(); var len:uint=char.length; for(var i:uint=0; i = 0 x0
16、001 & c 0 x07FF) outi=String.fromCharCode(0 xE0 | (c 12) & 0 x0F), 0 x80 | (c 6) & 0 x3F), 0 x80 | (c 0) & 0 x3F); else outi=String.fromCharCode(0 xC0 | (c 6) & 0 x1F), 0 x80 | (c 0) & 0 x3F); return out.join(); /utf8转 utf16 编码; public static function utf8to16(char:String):String var out:Array=new A
17、rray(); var len:uint=char.length; var i:uint=0; while(i 4) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 21 页 - - - - - - - - - case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: / 0 xxxxxxx outout.length=char.charAt(i - 1); break; case 12: case 1
18、3: / 110 x xxxx 10 xx xxxx var char2:int=char.charCodeAt(i+); outout.length=String.fromCharCode(c & 0 x1F) 6) | (char2 & 0 x3F); break; case 14: / 1110 xxxx 10 xx xxxx 10 xx xxxx var char3:int=char.charCodeAt(i+); var char4:int=char.charCodeAt(i+); outout.length=String.fromCharCode(c & 0 x0F) 12) |
19、(char3 & 0 x3F) 6) | (char4 & 0 x3F) 0); break; return out.join(); public static function autoReturn(str:String, c:int):String var l:int=str.length; if (l 0) return ; var i:int=c; var r:String=str.substr(0, i); while(i = l) r+=n; r+=str.substr(i, c); i+=c; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - -
20、- - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 21 页 - - - - - - - - - return r; public static function limitStringLengthByByteCount(str:String, bc:int, strExt:String=.):String if (str = null | str = ) return str; else var l:int=str.length; var c:int=0; var r:String=; for(var i:int=0; i 0 xffffff) c+=4;
21、else if (code 0 xffff) c+=3; else if (code 0 xff) c+=2; else +c; if (c bc) r+=str.charAt(i); else if (c = bc) r+=str.charAt(i); r+=strExt; break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 21 页 - - - - - - - - - else r+=strExt; break; return r; public stati
22、c function getCharsArray(targetString:String, hasBlankSpace:Boolean):Array var tempString:String=targetString; if (hasBlankSpace = false) tempString=trim(targetString); return tempString.split(); private static var CHINESE_MAX:Number = 0 x9FFF; private static var CHINESE_MIN:Number = 0 x4E00; privat
23、e static var LOWER_MAX:Number = 0 x007A; private static var LOWER_MIN:Number = 0 x0061; private static var NUMBER_MAX:Number = 0 x0039; private static var NUMBER_MIN:Number = 0 x0030; private static var UPPER_MAX:Number = 0 x005A; private static var UPPER_MIN:Number = 0 x0041; /* * 返回一段字符串的字节长度(汉字一个
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年ActionScript字符串操作参 2022 ActionScript 字符串 操作
限制150内