SoFunction
Updated on 2025-02-28

Determine the length of the string (optimized version) and occupies two characters in Chinese

I just saw the js method I wrote before: calculate the length of the string (2 characters in Chinese).

method:

var str = '123 Yes Yes';

var strArr = ('');

var count = 0;

for(){ **** }

………………………… (No more code, I'm tired!!)

After modification:

Copy the codeThe code is as follows:

var str = '123 Yes Yes';
var tmpStr = (/[\u4e00-\u9fa5]/gi,"aa");
//print