zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    自省改过
    c语言学习教程1之预定义代码
    tqdm进度条管理
    React-i18next切换中英文
    React怎样实现点击其他地方隐藏弹出的菜单
    遍历对象再取值,获得新值
    Web 用户体验设计提升指南
    antd vue form
    echarts 内容显示值在图中显示,不显示交互效果,只是静态图
    element-ui中el-table根据浏览器的缩放自适应宽度
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745956.html
Copyright © 2011-2022 走看看