日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Flex StringUtil工具类

發布時間:2023/12/9 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flex StringUtil工具类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近發現Flex處理字符串的工具類一共有三個,分別是:

  • mx.utils包下的StringUtil
  • mx.utils包下的RPCStringUtil
  • as3corelib類庫下的StringUtil
  • 下面分別整理及介紹下這三個工具類的用法:

    mx.utils包下的StringUtil

    1.trim()

    2.isWhitespace()?? 判斷是否是空白字符

    3.trimArrayElements()

    刪除數組中每個元素的開頭和末尾的所有空格字符,此處數組作為字符串存儲。

    4.substitute()

    使用傳入的各個參數替換指定的字符串內的“{n}”標記。

    示例:

    var str:String = "here is some info '{0}' and {1}"; trace(StringUtil.substitute(str, 15.4, true)); // this will output the following string: // "here is some info '15.4' and true"

    mx.utils包下的RPCStringUtil

    mx.utils下包StringUtil的子集,用法同StringUtil

    as3corelib類庫下的StringUtil

  • stringsAreEqual()??? 判斷字符串是否相等
  • trim()??? 去除首尾的空白字符
  • ltrim()?? 去除首部的空白字符
  • rtrim()?? 去除尾部的空白字符
  • beginsWith()?? 判斷字符串是否已該前綴開頭
  • endsWith()??? 判斷字符串是否已該后綴結尾
  • remove()??? 去除字符串中的部分字符
  • replace()?? 替換字符串中的部分字符
  • stringHasValue()? 判斷字符串是否有值
  • 代碼示例:

    <?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>

    輸出結果:


    總結

    以上是生活随笔為你收集整理的Flex StringUtil工具类的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。