Home > Web Front-end > JS Tutorial > 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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:32:32
Original
1538 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Python字符串转大小写问题
From 1970-01-01 08:00:00
0
0
0
javascript - HTML字符串排版
From 1970-01-01 08:00:00
0
0
0
linux - vim中查找字符串
From 1970-01-01 08:00:00
0
0
0
按换行符将字符串拆分成多行。
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template