• string tips


    1. wstring 向 char 转化

    std::wstring s2 ( L"Hello" );
    char *str = new char[255];
    sprintf(str,"%ls",s2.c_str());


    2. 定义一个 tstring
    typedef std::basic_string<TCHAR> tstring;
    

    3. 在 link  tab 之下加入以下,可以查看详细的链接lib的情况
    /verbose:lib

    4. string to TCHAR
    std::string str="something";
    TCHAR *param=new TCHAR[str.size()+1];
    param[str.size()]=0;
    //As much as we'd love to, we can't use memcpy() because
    //sizeof(TCHAR)==sizeof(char) may not be true:
    std::copy(str.begin(),str.end(),param);

        5. string.IndexOf 默认是区分大小写的    (C#)
        可以通过参数 System.StringComparison.OrdinalIgnoreCase ,忽略大小写
        另有System.StringComparison.CurrentCultureIgnoreCase等

    you could use IndexOf() and pass StringComparison.OrdinalIgnoreCase
    string title = "STRING";
    bool contains = title.IndexOf("string", StringComparison.OrdinalIgnoreCase) >= 0;
    

    Even better is defining a new extension method for string

    public static bool Contains(this string source, string toCheck, StringComparison comp) {
      return source.IndexOf(toCheck, comp) >= 0;
    }
    
    string title = "STRING";
    bool contains = title.Contains("string", StringComparison.OrdinalIgnoreCase);
    

    另一个解决方案:
    bool contains = Regex.Match("StRiNG to search", "string", RegexOptions.IgnoreCase).Success;

  • 相关阅读:
    耐心
    百度年会
    聊聊今年的春节联欢晚会
    网速调查
    热烈欢迎两位园友加盟
    遥远的路
    博客园博客程序架构设计图初稿
    [公告]社区与博客实现了登录整合
    博客园上海俱乐部第二次活动继续报道
    [收藏]《观察与思考》:相信中国,寻找下一个比尔·盖茨
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745956.html
Copyright © 2020-2023  润新知