使用swift代码编码url [英] encoding url using swift code
本文介绍了使用swift代码编码url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要用阿拉伯语发送一个URL,所以我需要在将它放入URL之前对其进行编码。我使用的是Swift代码。
I need to send an URL in Arabic language, so I need to encode it before I put it in URL. I am using Swift code.
以下是我真正需要的一个例子
Below is an example what i really need
var s = "www.example.com/السلام عليكم"
let url = NSURL(string : s)
所以单词(السلامعليكم)是阿拉伯字符,我想要发送。
So the word (السلام عليكم) is in Arabic characters that what I want to send.
推荐答案
Swift 2.0
let urlwithPercentEscapes = myurlstring.stringByAddingPercentEncodingWithAllowedCharacters( NSCharacterSet.URLQueryAllowedCharacterSet())
Swift 3
let urlwithPercentEscapes = myurlstring.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)
这篇关于使用swift代码编码url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文