複製程式碼 程式碼如下: <BR><BR><BR><script language="JavaScript"> <BR>/ /得到字元總數<BR>function getChars(str) {<BR> var i = 0;<BR> var c = 0.0;<BR> var unicode = 0;<BR> var len = 0;<BR> str == null || str == "") {<BR> return 0;<BR> }<BR> len = str.length;<BR> for(i = 0; i < len; i ) {<BR> unicode = str.charCodeAt(i);<BR> if (unicode < 127) { //判斷是單字元還是雙字元<BR> c = 1;<BR> } else { c = 1;<> } else { c = 1;<> } else { c = 1;< 2;<BR> }<BR> }<BR> return c;<BR>}<BR>function sb_strlen(str) {<BR> return getChars(str);<BR>/<BR>/<BR>/<BR>function sb_substr(str, startp, endp) {<BR> var i=0; c = 0; unicode=0; rstr = '';<BR> var len = str.length;< (str);<BR> if (startp < 0) {<BR> startp = sblen startp;<BR> }< p;// - ((str .charCodeAt(len-1) < 127) ? 1 : 2);<BR> }<BR> // 尋找起點<BR> = startp) {<BR> break;<BR> }<BR> = 1;<BR> } else {<BR> c = 2;<BR> }<BR> }<BR> // 開始取<BR> for(i = i; i < len; i ) {<BR> <BR> if (unicode < 127) {<BR> c = 1;<BR> } else {<BR> c = 2;<BR> }<BR> c = 2;<BR> }<BR> (c >= endp) {<BR> break;<BR> }<BR> }<BR> return rstr;<BR>}<BR>//呼叫範例:<BR>function 🎜>}<BR>//調用範例:<BR>function 🎜>}< short_filename = filename;<BR> if (sb_strlen(short_filename) > 61) {<BR> short_filename = sb_substr(short_stror, 0, 36) ' <BR> return short_filename;<BR>}<BR>var chara = 'ni你2好1啊! '<BR>js_self = chara.substr(4);<BR>test = sb_substr(chara,4);<BR>alert("js_self:" js_self "ext:" test);<BR> 複製程式碼 程式碼如下:function mb_strlen(str) { for(var i = 0; i len = str.charCodeAt(i) 255 ? (charset == ' utf-8' ? 3 : 2) : 1; } return len;} 已經輸入: