17
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Swift4 文字列の置換

Last updated at Posted at 2018-06-13

replacingOccurrencesを使用する。
ofに置換前、withに置換後の文字列を設定する。

import Foundation

// 置換前の文字列
var str: String = "ABC"

// 置換を行う
var newStr = str.replacingOccurrences(of: "A", with: "4")

// "4BC"と出力される。
print(newStr)
17
8
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
17
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?