Flex StringUtil工具类
5.repeat()
Returns a string consisting of a specified string concatenated with itself a specified number of times.
大部分SDK中无此函数,看其源码是用字符串相加实现的,不推荐使用。
6.restrict()
/** * Removes "unallowed" characters from a string. * A "restriction string" such as <code>"A-Z0-9"</code> * is used to specify which characters are allowed. * This method uses the same logic as the <code>restrict</code> * property of TextField. * * @param str The input string. * * @param restrict The restriction string. * * @result The input string, minus any characters * that are not allowed by the restriction string. * */
同上,大部分SDK中无此函数
mx.utils包下的RPCStringUtilmx.utils下包StringUtil的子集,用法同StringUtil
as3corelib类库下的StringUtil<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="#ffffff"layout="absolute"><mx:Script><![CDATA[import com.adobe.utils.StringUtil;]]></mx:Script><mx:VBox><mx:HBox><mx:Label text="input1"/><mx:TextInput id="input1" text="input1"/></mx:HBox><mx:HRule width="100%" height="1"/><mx:HBox><mx:Label text="is input1 begins with:"/><mx:TextInput id="beginsWith" text="i"/></mx:HBox><mx:HRule width="100%" height="1"/><mx:Text text="beginsWith:{ StringUtil.beginsWith(input1.text,beginsWith.text)}"/><mx:HRule width="100%" height="1"/><mx:Text text="input1 has value ?:{ StringUtil.stringHasValue(input1.text) }"/><mx:HRule width="100%" height="1"/><mx:HBox><mx:Label text="is input1 ends with:"/><mx:TextInput id="endsWith" text="1"/></mx:HBox><mx:Text text="endsWith:{ StringUtil.endsWith(input1.text,endsWith.text)}"/><mx:HRule width="100%" height="1"/><mx:HBox><mx:Label text="string to be removed from input1"/><mx:TextInput id="removeString"/></mx:HBox><mx:Text text="remove:{ StringUtil.remove(input1.text,removeString.text)}"/><mx:HRule width="100%" height="1"/><mx:HBox><mx:Label text="string to be replaced from input1"/><mx:TextInput id="replace"/></mx:HBox><mx:HBox><mx:Label text="string to be replace with"/><mx:TextInput id="replaceWith"/></mx:HBox><mx:Text text="replace:{ StringUtil.replace(input1.text,replace.text,replaceWith.text) }"/><mx:HRule width="100%" height="1"/><mx:Text text="ltrim:{ StringUtil.ltrim(input1.text)}"/><mx:Text text="trim:{StringUtil.trim(input1.text)}"/><mx:Text text="rtrim:{StringUtil.rtrim(input1.text)}"/><mx:HRule width="100%" height="1"/><mx:HBox><mx:Label text="input2"/><mx:TextInput id="input2" text="input1"/><mx:Label text="is case sensitive?"/><mx:CheckBox id="caseSensitive" selected="true"/></mx:HBox><mx:Text text="input1 and input2 are equal?:{ StringUtil.stringsAreEqual(input1.text,input2.text,caseSensitive.selected)}"/></mx:VBox></mx:Application>输出结果:
注:如果当初Adobe开发团队将这些方法直接加在String类中能有多好啊,鄙视之!!!
<script type="text/javascript"></script>