Ext.String 方法


1.Ext.String.htmlEncode(value);  編碼字符串,對其中特殊字符進行轉義

xt.String.htmlEncode("hello'world");    //"hello'world"

2.Ext.String.htmlDecode(value);  解碼字符串,對其中的轉義字符進行還原

Ext.String.htmlDecode("hello'world");    //"hello'world"

3.Ext.String.urlAppend(url,string)  追加內容到查詢字符中,?相連

Ext.String.urlAppend("www.baidu.com","a=1");    //"www.baidu.com?a=1"

4.Ext.String.trim(string)  去掉字符串開頭和結尾位置的空格

Ext.String.trim(" hello world ");    //"hello world"

5.Ext.String.capitalize(string)  首字母大寫

Ext.String.capitalize("hello");    //"Hello"

6.Ext.String.ellipsis(value,length,word)  截斷字符串並在結尾處添加省略號  value 原始字符串 length 保留長度 word 設置為true則試圖保留完整單詞

Ext.String.ellipsis("my name is shi",3,false);    //"..."
Ext.String.ellipsis("my name is shi",3,true);    //"..."
Ext.String.ellipsis("my name is shi",6,false);    //"my ..."
Ext.String.ellipsis("my name is shi",6,true);    //"my..."
Ext.String.ellipsis("my name is shi",8,false);    //"my na..."
Ext.String.ellipsis("my name is shi",8,true);    //"my..."

7.Ext.String.escapeRegex(string)  將原始字符串中的-.*+?^${}()[]\進行替換

Ext.String.escapeRegex("hello -.*+?^${}()[]");    //"hello \-\.\*\+\?\^\$\{\}\(\)\[\]"

8.Ext.String.toggle(string,value,other)  對比兩個字符串是否相等,相等返回other,不相等返回value

Ext.String.toggle("abc","abc","相等");    //"相等"
Ext.String.toggle("abc","cba","相等");    //"cba"

9.Ext.String.leftPad(string,size,[character])  在字符串左邊填充指定字符串

Ext.String.leftPad("12 3",5,"0000");    //"000012 3"

10.Ext.String.format(string,value1,value2)  定義帶標記的字符串,並用傳入的字符替換標記。 每個標記必須是唯一的,而且必須要像{0},{1}...{n}這樣地自增長

var cls = 'my-class', text = 'Some text';
Ext.String.format('<div class="{0}">{1}</div>', cls, text);    //'<div class="my-class">Some text</div>'

 

 

 

 

 

 

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM