TypeScript - 字串 localeCompare()



此方法返回一個數字,指示引用字串在排序順序中是在給定字串之前、之後還是與之相同。

語法

string.localeCompare( param )

引數詳情

param − 要與字串物件進行比較的字串。

返回值

  • 0 − 如果字串 100% 匹配。

  • 1 − 不匹配,並且引數值在區域設定排序順序中位於字串物件的值之前。

  • 負值 − 不匹配,並且引數值在本地排序順序中位於字串物件的值之後。

示例

var str1 = new String( "This is beautiful string" );
  
var index = str1.localeCompare( "This is beautiful string");  

console.log("localeCompare first :" + index );

編譯後,它將在 JavaScript 中生成相同的程式碼。

其輸出如下:

localeCompare first :0
typescript_strings.htm
廣告

© . All rights reserved.