「Swift」文字列を結合するサンプル

書式
方法1 +演算子
let 変数名3 =変数名1 + 変数名2

方法2 +=演算子
変数名3+="文字列"

使用例

var strA = "Study Skill"
let strB = "Become Smart"

let resA = strA + ", " + strB + "!"
let resB = "\(strA), \(strB)!"

strA += "# "
strA += strB
strA += "&"
let resC = strA

print("+演算子の方法")
print(resA)
print("+=演算子の方法")
print(resB)
print(resC)

実行結果

+演算子の方法
Study Skill, Become Smart!
+=演算子の方法
Study Skill, Become Smart!
Study Skill# Become Smart&

 

Swift

Posted by arkgame