The code copy is as follows: function(s){
return Math.ceil(s.replace(/[/u4e00-/u9fa5]/g, 'xx').length / 2);
}
You can also use (/[^/x00-/xff]/g,'**'), which replaces double-byte characters with '**'
(/[/u4e00-/u9fa5]/g, '**') Is this a replacement of Chinese characters with '**', is it edited by /u4e00-/u9fa5 Chinese unicode
The above is the entire content of this article. For more information about JavaScript, you can check out: "JavaScript Reference Tutorial" and "JavaScript Code Style Guide". I also hope that everyone will support Wulin.com more.