|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 | package main
import "fmt"
func main() {
    var str1 string = "Golang"
    var str2 string = "World"
    var str3 string = "고프로그래밍"
    
    fmt.Println("Example 1 : ", str1[0], str1[1], str1[2], str1[3], str1[4], str1[5])
    fmt.Println("Example 1 : ", str2[0], str2[1], str2[2], str2[3], str2[4])
    fmt.Println("Example 1 : ", str3[0], str3[1], str3[2], str3[3], str3[4], str3[5])
    
    // Example 2
    fmt.Println("########################################")
    fmt.Printf("Example 2 : %c %c %c %c %c %c\n", str1[0], str1[1], str1[2], str1[3], str1[4], str1[5])
    fmt.Printf("Example 2 : %c %c %c %c %c\n", str2[0], str2[1], str2[2], str2[3], str2[4])
    fmt.Printf("Example 2 : %c %c %c %c %c %c\n", str3[0], str3[1], str3[2], str3[3], str3[4], str3[5]) // 한글깨짐
    
    conStr := []rune(str3)
    fmt.Printf("Example 2 : %c %c %c %c %c %c\n", conStr[0], conStr[1], conStr[2], conStr[3], conStr[4], conStr[5]) // 한글 정상 출력
    
    // Example 3
    fmt.Println("########################################")
    for i, char := range str1 {
        fmt.Printf("Example 3 : %c(%d)\t", char, i)
    }
    fmt.Println()
    
    fmt.Println("########################################")
    for i, char := range  str2 {
        fmt.Printf("Example 4 : %c(%d)\t", char, i)
    }
}
 |