determine the byte length of a Chinese character
function () { varthis. Match (/[^\x00-\xff]/g); return this. length + = Chinesechar? chinesechar.length:0// 9
determine if there are any duplicate characters in a string
// method of using string traversal str = str.tolowercase (); for (var i = 0; i < str.length; i++) { if (Str.indexof (Str.charat (i), i + 1) >= 0) { c10/>returnfalse; // Use the regular expression /^.* (.). *\1/i.test (' Hi '); // false // true
calculate a percentage of two values
function getpercentage (NUM1, num2) { return math.round (NUM1/NUM2 * 10000)/+ '% ';} Getpercentage (// "40%"/ / "249.75%"
split a numeric amount with commas
function () { returnthis. Split ("). Reverse (). Join ('function() { return this. StrReverse (). Replace (/(\d+\.)? (\d{1,3})/g, ' $1$2, '). StrReverse (). substring (1' 1200.30 '. Usecommasplitamount (); // "1,200.30" // "10,088,561"
JavaScript snippet-string "original" 2016-2-19