NSURL URLWithString: is null with non-english accented characters

前端 未结 5 1370
孤独总比滥情好
孤独总比滥情好 2020-11-29 01:48

I have the following string...

NSString *googleSearchString = @\"http://www.google.com/search?q=lyrics+%22Tænder+På+Dig%22+%22Jakob+Sveistrup%22\";
         


        
5条回答
  •  一整个雨季
    2020-11-29 02:25

    Using Swift 2.2

    For escaping non-english characters, for example: to make an URL request do:

    let urlPath = path.URLString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())

    Here urlPath is an Optional and path is your original url (the one with non-english characters)

提交回复
热议问题