91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

go語言怎么遍歷字符串

小億
94
2024-04-02 17:37:03
欄目: 編程語言

在Go語言中,可以使用range關鍵字來遍歷字符串。下面是一個簡單的例子:

package main

import (
	"fmt"
)

func main() {
	str := "Hello, World!"

	for index, char := range str {
		fmt.Printf("Character at index %d is %c\n", index, char)
	}
}

在上面的例子中,我們使用range關鍵字遍歷字符串str,并輸出每個字符的索引和字符本身。輸出結果為:

Character at index 0 is H
Character at index 1 is e
Character at index 2 is l
Character at index 3 is l
Character at index 4 is o
Character at index 5 is ,
Character at index 6 is  
Character at index 7 is W
Character at index 8 is o
Character at index 9 is r
Character at index 10 is l
Character at index 11 is d
Character at index 12 is !

0
凯里市| 无为县| 宜川县| 六枝特区| 岗巴县| 巴南区| 彰武县| 井陉县| 黄石市| 孟村| 阳谷县| 富源县| 台东县| 铜鼓县| 永德县| 方山县| 桐城市| 宁远县| 翁源县| 九寨沟县| 巍山| 台南县| 澜沧| 华宁县| 昭觉县| 都昌县| 图们市| 德格县| 准格尔旗| 赣榆县| 银川市| 古蔺县| 拉萨市| 常熟市| 墨脱县| 锦州市| 措勤县| 汪清县| 壤塘县| 大连市| 婺源县|