πŸ“š μ½”λ”©ν…ŒμŠ€νŠΈ/Swift

[Swift] ReplacingOccurrences ( λ¬Έμžμ—΄ μΉ˜ν™˜ )

deep_lee 2023. 11. 2. 16:04

πŸ“š λ¬Έμžμ—΄ λ‚΄ νŠΉμ •λ¬Έμž λ³€κ²½ (μΉ˜ν™˜)

 

 

 

 

 

ReplacingOccurrences

λ¬Έμžμ—΄μ„ λŒ€μ²΄ν•˜μ—¬ μƒˆ λ¬Έμžμ—΄μ„ λ°˜ν™˜ν•œλ‹€.

 

- of target : λ°”κΏ€ λ¬Έμžμ—΄

- with replacement : λŒ€μ²΄ν•  λ¬Έμžμ—΄

 

 

μ‚¬μš©μ˜ˆμ‹œ

let str = "Bye Nice to meet you"
let result = str.replacingOccurrences(of: "Bye", with: "Hello")
print(result) // "Hello Nice to meet you"

 

of: 에 μžˆλŠ” "Bye"λ₯Ό "Hello"둜 λ³€κ²½ν•˜λŠ” μ½”λ“œμ΄λ‹€.