字符串拆分与Unicode [英] String Split With Unicode

查看:109
本文介绍了字符串拆分与Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我一直在网上搜索此解决方案。

First off I been searching the web for this solution.

如何:

<''.split('');

> ['','','']

只需表达我喜欢的内容去做。但也有其他Unicode字符,如poo。

Simply express of what I'll like to do. But also with other Unicode characters like poo.

推荐答案

JavaScript存在Unicode问题 ,在ES6中,您可以使用新的<$轻松完成此操作c $ c> ... 传播运营商。这会导致字符串迭代器(另一个新的ES6特性)在内部使用,并且因为迭代器设计用于处理代码点而不是UCS-2 / UTF-16代码单元,所以它可以按照您想要的方式工作:

As explained in JavaScript has a Unicode problem, in ES6 you can do this quite easily by using the new ... spread operator. This causes the string iterator (another new ES6 feature) to be used internally, and because that iterator is designed to deal with code points rather than UCS-2/UTF-16 code units, it works the way you want:

这篇关于字符串拆分与Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆