투케이2K

21. (swift/xcode) 특정 문자열로 시작 및 종료 여부 확인 실시 - hasPrefix , hasSuffix 본문

Swift

21. (swift/xcode) 특정 문자열로 시작 및 종료 여부 확인 실시 - hasPrefix , hasSuffix

투케이2K 2021. 10. 20. 08:29
반응형

[개발 환경 설정]

개발 툴 : XCODE

개발 언어 : SWIFT


[소스 코드]

     /*
     [요약 설명]
     1. hasPrefix : string 형태 문자열에서 특정 문자로 시작하는 지 확인해줍니다
     2. hasSuffix : string 형태 문자열에서 특정 문자로 종료하는 지 확인해줍니다
     3. hasPrefix , hasSuffix 는 포함 여부를 true , false 값으로 반환해줍니다
     */
    
    
    // [테스트 메인 함수 정의 실시]
    func testMain() {
        print("")
        print("===============================")
        print("[testMain : Program Start]")
        print("===============================")
        print("")
        
        // [특정 문자열 선언 실시]
        let str_data : String = "http://www.google.com"
        
        // [특정 문자열 시작 문자 확인 실시]
        let httpStart : Bool = str_data.hasPrefix("http")
        let httpsStart : Bool = str_data.hasPrefix("https")
        
        // [특정 문자열 종료 문자 확인 실시]
        let comEnd : Bool = str_data.hasSuffix("com")
        let krEnd : Bool = str_data.hasSuffix("kr")
        print("")
        print("===============================")
        print("원본 : ", str_data)
        print("http 시작 : ", httpStart)
        print("https 시작 : ", httpsStart)
        print("com 종료 : ", comEnd)
        print("kr 종료 : ", krEnd)
        print("===============================")
        print("")
    }

 


[결과 출력]


[요약 설명]

/*

[요약 설명]

1. hasPrefix : string 형태 문자열에서 특정 문자로 시작하는 지 확인해줍니다

2. hasSuffix : string 형태 문자열에서 특정 문자로 종료하는 지 확인해줍니다

3. hasPrefix , hasSuffix 는 포함 여부를 true , false 값으로 반환해줍니다

*/


 

반응형
Comments