<script> <br>function subString(str, len, hasDot) <br>{ <br>var newLength = 0; <br>var newStr = ""; <br>var chineseRegex = /[^x00-xff]/g; <br>var singleChar = ""; <br>var strLength = str.replace(chineseRegex,"**").length; <br>for(var i = 0;i < strLength;i ){ <BR>singleChar = str.charAt(i). toString(); <BR>if(singleChar.match(chineseRegex) != null){ <BR>newLength = 2; <BR>}else{ <BR>newLength ; <BR>} <BR>if(newLength > len){ <br>break; <br>} <br>newStr = singleChar; <br>} <br><br>if(hasDot && strLength > len){ <br>newStr = "..."; <br>} <br>return newStr; <br>} <br>alert(subString("js intercepts Chinese and English strings without garbled characters",10,true)); <br></script>