0
0

More than 1 year has passed since last update.

Go言語 stringsパッケージ

Posted at

文字列チェック

■文字列に「,」が含まれているかをチェック
if strings.Contains("red,blue", ",") {
    fmt.Println("複数")
} else {
    fmt.Println("単数")
}

// 複数

文字列変換

■「,」区切りの文字列を配列(スライス)に変換
colorArr := strings.Split("red,blue", ",")
for _, v := range colorArr {
    fmt.Print(v + "\n")
    // red
    // blue
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0