Dev/SWIFT
[Swift] replacingOccurrences(of:with:)
Laena
2024. 1. 30. 07:18
replacingOccurrences(of:with:)
특정 문자열에 해당하는 곳의 문자열 치환
self에서 of 문자열 부분을 with으로 변경
replacingOccurrences(of:with:) | Apple Developer Documentation
Returns a new string in which all occurrences of a target string in the receiver are replaced by another given string.
developer.apple.com
let sampleStr = "12345"
let newStr = sampleStr.replacingOccurrences(of: "2", with: "vv")
print(newStr) // 1vv345