in my app while fetch data from server i am getting image url and then i load that image in my imageview. its working perfectly but when my url getting arabic character its getting crash. so how can i find out that my urlstring is contain arabic character or not?
在我的应用程序从服务器获取数据时,我正在获取图像网址,然后我在我的imageview中加载该图像。它的工作完美,但当我的网址得到阿拉伯字符时它会崩溃。那我怎么能发现我的urlstring是否包含阿拉伯字符?
i only want A to Z and number and / and - and . in my urlstring
我只想要A到Z和数字和/和 - 和。在我的urlstring中
right now i just avoiding crash by this code but its not proper thing
现在我只是避免这个代码崩溃,但它不正确的事情
this is my code
这是我的代码
if (newimage.characters.count != 0)
{
if (newimage != "http://www.******.**/****/*****/uploads/2015/**/سيباستيان-فيتيل-فيراري-فورمولا-1.jpg")
{
ImageLoader.sharedLoader.imageForUrl(newimage) { (images, url) -> () in
if (images != nil)
{
print(images)
cell.image1.image = images!
}
}
}
else
{
print("XYZ")
}
}
1 个解决方案
#1
0
You can use regex to check your URL:
您可以使用正则表达式检查您的网址:
let regex = try! NSRegularExpression(pattern: "[^A-Za-z0-9 \\-\\.\\:\\/]", options: [])
let firstMatch = regex.rangeOfFirstMatchInString(newImage, options: [], range: NSMakeRange(0, newImage.characters.count))
if firstMatch.location != NSNotFound {
// Invalid character found
}
#1
0
You can use regex to check your URL:
您可以使用正则表达式检查您的网址:
let regex = try! NSRegularExpression(pattern: "[^A-Za-z0-9 \\-\\.\\:\\/]", options: [])
let firstMatch = regex.rangeOfFirstMatchInString(newImage, options: [], range: NSMakeRange(0, newImage.characters.count))
if firstMatch.location != NSNotFound {
// Invalid character found
}