作者KC73 (肯先生)
看板Ajax
标题[ js ] 请教计算中/英文字数的问题..
时间Sat Feb 2 19:55:30 2008
请教诸位..
如果要即时检查输入文章的字数, 一般都用 elm.value.length 计算, 但是
这样算法对英文不太公平...
This is an apple. <== 17
这是苹果 <== 4
不知道有没有前辈做过, 中文算字, 英文算 word (不是 letter) 的?
This is an apple. <== 4
这是苹果 <== 4
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.166.139.236
1F:→ gpmm:用 string.split (' ').length 02/02 20:05
2F:推 TonyQ:可能要考虑分隔符号 XD 02/02 20:14
3F:推 zi:用RegExp 例:var a = "中文测试 this is a word"; 02/03 19:00
4F:→ zi:a.match(/[\u4E00-\u9FA5]|\w+/g).length 02/03 19:01
5F:→ KC73:感谢, 在下试试看罗~ 02/07 03:52