Home  >  Article  >  Web Front-end  >  Determining the length of a string (optimized version) Chinese takes two characters_javascript skills

Determining the length of a string (optimized version) Chinese takes two characters_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:32:321472browse

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

Method:

var str = '123YesYesYes';

var strArr = str.split('');

var count = 0;

for(strArr.length){ **** }

…………(No more coding, I’m tired!!)

After modification:

Copy code The code is as follows:

var str = '123YesYesYes';
var tmpStr = str.replace(/[u4e00-u9fa5]/gi,"aa");
//print
tmpStr.length
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn