[go] Bytes 패키지의 문자열 함수

목차

Bytes 패키지란?

Bytes 패키지는 바이트 배열을 조작하고 다양한 기능을 제공하는 Go 언어의 표준 라이브러리입니다.

Bytes 패키지의 문자열 함수

ToLowerCase 함수

import "bytes"

func main() {
    str := []byte("HELLO")
    lower := bytes.ToLower(str)
    fmt.Println(string(lower)) // 출력: hello
}

ToLower 함수는 문자열을 소문자로 변환합니다.

ToUpperCase 함수

import "bytes"

func main() {
    str := []byte("hello")
    upper := bytes.ToUpper(str)
    fmt.Println(string(upper)) // 출력: HELLO
}

ToUpper 함수는 문자열을 대문자로 변환합니다.

Contains 함수

import "bytes"

func main() {
    str := []byte("gopher")
    sub := []byte("go")
    if bytes.Contains(str, sub) {
        fmt.Println("Substring found")
    }
}

Contains 함수는 문자열에 특정 부분 문자열이 포함되어 있는지 확인합니다.

Join 함수

import "bytes"

func main() {
    strs := [][]byte{[]byte("Golang"), []byte("is"), []byte("awesome")}
    result := bytes.Join(strs, []byte(" "))
    fmt.Println(string(result)) // 출력: Golang is awesome
}

Join 함수는 바이트 배열들을 구분자를 이용하여 하나의 바이트 배열로 결합합니다.

이러한 Bytes 패키지의 함수들을 활용하여 문자열 조작을 보다 유연하게 처리할 수 있습니다.

참조: Go 언어 공식 문서


본 문서는 Go 언어에서의 Bytes 패키지의 문자열 함수에 대해 설명합니다.