mootools架構【五】-String篇:方法完全解析

來源:互聯網
上載者:User

說明:String大概是使用頻率最高的資料類型了,在各個javascript架構中,都或多或少的對String進行了擴充,來提供一些十分方便的方法來處理日常應用。mootools也不例外,String.js中主要實現了這些對String的擴充,還稍微帶了點對Array和Number的擴充。

--------------------------------String.js---------------------------------------

1.方法:test

作用:對字串執行Regex匹配

例子:

var x = "Hello,world!".test('hello'); //false
var y = "Hello,world!".test('hello','i'); //true,'i'是Regex參數,表示 忽略大小寫.注意'g'在這裡無效
var z = "Hello,world!".test(/H.*?o/); //true

2.方法:toInt to-->int

作用:把字串轉換成整數,如果非數字,則返回NaN

例子:

var x0 = "1.12".toInt(); //1
var x1 = "1".toInt(); //1
var x2 = "1px".toInt(); //1
var x3 = "10xxx".toInt(); //10
var x4 = "x10xxx".toInt(); //NaN
var x5 = "020".toInt(); //16
var x6 = "0xFF".toInt(); //255

3.方法:toFloat

作用:把字串轉換成浮點數

例子:

var x0="1.12".toFloat();  //1.12

4.方法:camelCase

作用:把以"-"分隔的字串,如"my-work",轉換成"myWork"這樣的形式

例子:

var x = "my-work".camelCase(); //myWork
var y = "My-Work".camelCase(); //MyWork

hyphenate

作用:把形如"myNotePad"形式的字串,轉換成"my-note-pad"這樣的形式

例子:

var x="myNotePad".hyphenate();  //my-note-pad

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.