简体   繁体   中英

Emojis in VSCode

Im trying to edit the following array of emojis in dart, I tried emoji extensions in VSCode but none are working for this line of code.

const _emojis = ['😃','🤓','😁','😂','😞'];

Dart Strings appear to be UTF-16 sequences . So find the UTF sequences for those emoji and use them as described in that link.

The simplest naïve case, that of Unicode code points, would be:

const _emojis = ['\u{1f605}','\u{1f606}','\u{1f607}','\u{1f608}','\u{1f609}'];

for (var i = 0;i<_emojis.length;i++) {
   print("Position $i : ${_emojis[i]} ");
}

There are helpers for this as well:

For a character outside the Basic Multilingual Plane (plane 0) that is composed of a surrogate pair, runes combines the pair and returns a single integer

In fact, you are recommended to not use raw lists for this as it can lead to problems down the road . The Language Tour specifically calls this out:

Note: Be careful when manipulating runes using list operations. This approach can easily break down, depending on the particular language, character set, and operation.

Also, see the Dart String tutorial and the Language Tour (which actually shows a solution to this exact question).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM