Skip to content

Instantly share code, notes, and snippets.

@jikeytang
Created June 19, 2014 01:55
Show Gist options
  • Select an option

  • Save jikeytang/3f5e9c0118c27178bc8c to your computer and use it in GitHub Desktop.

Select an option

Save jikeytang/3f5e9c0118c27178bc8c to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140619-题目1
求一个字符串的字节长度;
//假设一个中文占两个字节
/*var str = 'hello中国';
PS:
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。
```javascript
// you code
```
2. 粘贴代码时请使用shift+tab,缩进前面的空白。
@zjhsd2007
Copy link
Copy Markdown

var str = 'Hello中国',n =  str.match(/[\u4e00-\u9fa5]/g)
return str.length + (n ? n.length : 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment