簡體   English   中英

swift 2等同於swift 3“字符串包含”功能嗎? 由npn.dev

[英]What is the swift 2 equivalent to the swift 3 “string contains” function? by npn.dev

您好,我想知道Swift 3的等效功能

mySong.contains

Xcode 7上的Swift 2(因為我想為iPhone 4創建一個應用程序)。 對不起,我是英語,因為我是法語...,谷歌翻譯幫助我

我的代碼:

func gettingSongName(){

    let folderURL = NSURL(fileURLWithPath: NSBundle.mainBundle().resourcePath!)

    do{

        let songPath = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(folderURL, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)

        for song in songPath{

            var mySong = song.absoluteString

            if mySong.contains(".mp3") { // Value of type 'String' has no member 'contains'

                let findString = mySong.components(separatedBy: "/") // Value of type 'String' has no member 'components'
                mySong = findString[findString.count-1]
                mySong = mySong.replacingOccurrences(of: "%20", with: " ") // Value of type 'String' has no member 'replacingOccurences'
                mySong = mySong.replacingOccurrences(of: "e%CC%81", with: "é") // Value of type 'String' has no member 'replacingOccurences'
                mySong = mySong.replacingOccurrences(of: "e%CC%82", with: "ê") // Value of type 'String' has no member 'replacingOccurences'
                mySong = mySong.replacingOccurrences(of: ".mp3", with: "") // Value of type 'String' has no member 'replacingOccurences'
                songs.append(mySong)
                print(mySong)

            }

        }

        myTableView.reloadData()

    }catch{

    }

}

預先感謝您, npn.dev

我在Swift 2和Xcode 7.3.1中使用range string方法

let string = "This is only a test"

if string.rangeOfString("only") != nil {
 print("yes")
}

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM