中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

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
芜湖县| 乌拉特中旗| 舞钢市| 金寨县| 阳朔县| 华阴市| 开化县| 青冈县| 武平县| 黔东| 奇台县| 桐梓县| 盐亭县| 恩施市| 新密市| 苗栗市| 灵川县| 哈尔滨市| 清原| 蛟河市| 云南省| 长子县| 专栏| 江西省| 习水县| 灵台县| 长兴县| 靖州| 启东市| 缙云县| 九寨沟县| 邻水| 遂溪县| 新龙县| 历史| 彝良县| 垫江县| 铜梁县| 华蓥市| 泗水县| 桐庐县|