dev._.note

[Swift] replacingOccurrences(of:with:) 본문

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

 

 

'Dev > SWIFT' 카테고리의 다른 글

[Swift] 통신 시 인터넷 권한 추가 (info.plist 설정)  (0) 2024.02.01
[Swift] MVC와 MVVM 장점과 단점  (0) 2024.01.30
[Swift-UI] 화면전환하기  (0) 2024.01.11
[Swift] lazy란?  (0) 2024.01.10
[Swift] Decodabe, Encodable, Codable  (0) 2024.01.09