알고리즘/Programmers

[Swift_Programmers] rny_string

YEN_ 2023. 11. 18. 00:52

 

프로그래머스 알고리즘

 

문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/181863


풀이    

 

import Foundation

func solution(_ rny_string:String) -> String {
    
    let answer = rny_string.replacingOccurrences(of:"m",with:"rn")
    
    return answer
}

 

 


중요 개념    

  • m이라는 문자를 rn이라는 다른 문자로 치환하는 문제이다
  • 문자열 치환 메소드를 사용한다
replacingOccurrences(of:with:)
  • of: "기존 문자"
  • with: "바꿀 문자"

 

https://developer.apple.com/documentation/foundation/nsstring/1412937-replacingoccurrences

 

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