zoukankan      html  css  js  c++  java
  • string代替

        NSString * t = @"EMMS_Files\Business\WORRF\TXT\20170403\5379774001.pdf";

        

        NSString * a = [t stringByReplacingOccurrencesOfString:@".pdf" withString:@".jpg"];

    stringByAddingPercentEscapesUsingEncoding(只对 `#%^{}[]|"<> 加空格共14个字符编码,不包括”&?”等符号), ios9将淘汰,建议用stringByAddingPercentEncodingWithAllowedCharacters方法

    stringByAddingPercentEncodingWithAllowedCharacters需要传一个

    NSCharacterSet对象(关于  NSCharacterSet 这篇 文章说的很好)

    如[NSCharacterSet  URLQueryAllowedCharacterSet]

    URLFragmentAllowedCharacterSet  "#%<>[]^`{|}

    URLHostAllowedCharacterSet      "#%/<>?@^`{|}

    URLPasswordAllowedCharacterSet  "#%/:<>?@[]^`{|}

    URLPathAllowedCharacterSet      "#%;<>?[]^`{|}

    URLQueryAllowedCharacterSet    "#%<>[]^`{|}

    URLUserAllowedCharacterSet      "#%/:<>?@[]^`

    (2)网络访问请求:中文空格字符解码

    stringByRemovingPercentEncoding  ----  xcode7可能会提示要将stringByAddingPercentEscapesUsingEncoding替换成此方法,要根据是否是解码来区分

    */

    //代替stringByAddingPercentEscapesUsingEncoding

    let customAllowedSet =  NSCharacterSet(charactersInString:"`#%^{}"[]|\<> ").invertedSet

        NSString *url = [NSString stringWithFormat:@"whatsapp://send?text=%@", [msg stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]];

        NSURL *whatsappURL = [NSURL URLWithString: url];

    一天一章
  • 相关阅读:
    使脱排油烟机能够听懂你的话(超级简单的方法)
    解决手机无法连接【小米AI音箱】播放音乐问题
    相机稳定器使用注意点
    Scrapy基本命令
    Linux环境下的Scala环境搭建
    Linux基本操作
    MySQL常用操作
    PySpark笔记
    Linux环境下配置及启动Hadoop(伪集群)
    idea: unable to import maven project
  • 原文地址:https://www.cnblogs.com/hangman/p/6911747.html
Copyright © 2011-2022 走看看