美文网首页
ios 确保NSUrl不为nil

ios 确保NSUrl不为nil

作者: SimpleTogether | 来源:发表于2016-12-09 14:24 被阅读48次

    1.先去空格

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

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

    2.转码

    urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    3.转成NSUrl

    NSURL*url = [NSURL URLWithString:urlString];

    相关文章

      网友评论

          本文标题:ios 确保NSUrl不为nil

          本文链接:https://www.haomeiwen.com/subject/gpiemttx.html