亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

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
溧阳市| 玉田县| 云阳县| 元朗区| 曲周县| 离岛区| 阿荣旗| 贵南县| 南阳市| 林西县| 夏邑县| 巴里| 岳阳市| 麻阳| 曲水县| 温泉县| 房产| 汉沽区| 永吉县| 安康市| 永清县| 彰化县| 葫芦岛市| 桂平市| 即墨市| 锡林浩特市| 武乡县| 天祝| 漳平市| 玉山县| 临夏市| 宁阳县| 且末县| 乌拉特后旗| 大渡口区| 宝坻区| 始兴县| 庄浪县| 留坝县| 定襄县| 临沧市|