xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Java String length & Unicode All In One

Java String length & Unicode All In One

emoji 组合 👨🏻‍💻 = 👨🏻‍🦱 + 💻

UTF-8 / UTF-16

public class HelloWorld {
    public static void main(String []args) {
       String s = "java";
       System.out.println(s.length());
       // Unicode length
       System.out.println("Hello World".length());
       System.out.println("✅".length());
       System.out.println("👨🏻‍💻".length());
    }
}

/*
4
11
1
7

*/

image

demos

  1. java

java


public class HelloWorld {
  public static void main(String []args) {
    System.out.println("👨🏻‍💻".length());
    String emoji = "👨🏻‍💻";
    for(int i=0; i< emoji.length(); i++){
      char c = emoji.charAt(i);
      System.out.println(c);
    }
  }
}

/*
7
?
?
?
?
‍
?
?


*/

  1. js

js

// 四合一 emoji
const emoji = "👨🏻‍💻";

for (let char of emoji) {
  console.log(`char =`, char);
}

// char = 👨
// char = 🏻
// char = ‍
// char = 💻

image

java tutorials

https://www.runoob.com/java/java-tutorial.html

https://codegym.cc/quests/lectures

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

java REPL

https://www.runoob.com/try/runcode.php?filename=HelloWorld&type=java

https://juejin.cn/post/6844904036873814023



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-02-01 21:44  xgqfrms  阅读(17)  评论(3编辑  收藏  举报