ios 确保NSUrl不为nil

2016-12-09  本文已影响48人  SimpleTogether

1.先去空格

NSString *urlString = @"http://sfsdfsdfsd sdfsdfsfsdf你好";

urlString = [urlString stringByReplacingOccurrencesOfString:@" "withString:@""];

2.转码

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

3.转成NSUrl

NSURL*url = [NSURL URLWithString:urlString];

上一篇下一篇

猜你喜欢

热点阅读