Search

숫자 문자열과 영단어

상태
완료
담당자
네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다.
다음은 숫자의 일부 자릿수를 영단어로 바꾸는 예시입니다.
1478 → "one4seveneight"
234567 → "23four5six7"
10203 → "1zerotwozero3"
import Foundation func solution(_ s:String) -> Int { var result = s let table = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] for i in 0..<table.count { result = result.replacingOccurrences(of: table[i], with: String(i)) } return Int(result)! }
Swift
복사

replaceOccurrences

import Foundation let string = "안-녕하세요" string.replacingOccurrences(of: "-", with: "")
Swift
복사
func replacingOccurrences(of target: String, with replacement: String) -> String // string안에 들어간 “-“를 ““로 바꾸어 새로운 문자열로 반환해 달라.
Swift
복사
func hideName(myName: String) -> String { let secontIndex = myName[myName.index(after: myName.startIndex)] return myName.replacingOccurrences(of: String(secontIndex), with: "*") } hideName(myName: "홍길동") // return : "홍*동"
Swift
복사