go语言遍历中文字符串如何实现?

go语言遍历中文字符串如何实现


白板的微信
浏览 1086回答 1
1回答

一只甜甜圈

用length()方法、charAt方法结合for循环就行了,package com.golden.test;public class TestString {&nbsp;&nbsp; &nbsp;public static void main(String[] args) {&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;String str = "你叫神马?我叫Tesson.";&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for (int i = 0; i < str.length(); i++) {&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;char&nbsp; item =&nbsp; str.charAt(i);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println(item);&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}}
打开App,查看更多内容
随时随地看视频慕课网APP