SoFunction
Updated on 2025-03-06

JS function code for Chinese string intercept


Code
// Calculate the string length
= function() {
    var len = 0;
    for (var i = 0; i < ; i++) {
        if ((i) > 255 || (i) < 0) len += 2; else len ++;
    }
    return len;
}
//Split the string into characters and store it in the array
= function(){
   var chars = new Array();
   for (var i = 0; i < ; i++){
       chars[i] = [(i, 1), (i)];
   }
   = chars;
   return chars;
}
//Judge whether a character is a Chinese character
= function(i){
   if ((i) > 255 || (i) < 0)
       return true;
   else
       return false;
}
//Intercept the string (from start byte to end byte)
= function(start, end){
   var len = 0;
   var str = "";
   ();
   for (var i = 0; i < ; i++) {
       if([i][1])
           len += 2;
       else
           len++;
       if (end < len)
           return str;
       else if (start < len)
           str += [i][0];
   }
   return str;
}
//Intercept the string (intercept the length bytes from the start byte)
= function(start, length){
   return (start, start + length);
}