• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

落雪凝辰

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

C# 大小写转换,方便index of

ToUpper:小写转大写
ToLower:大写转小写

 

例:

string str=120cm*150g/m2;从中取出120和150,但是又要规避大小写问题,这时候就需要将str转换为大写,然后index of的时候使用大写进行查找

 string std ="120cm*150g/cm2".ToUpper();//全部转换为大写,方便下面查找
                int sort1 = std.IndexOf("CM");
                int sort2 = std.IndexOf("*");
                int sort3 = std.IndexOf("G/M");
                string width = string.Empty;
                string weight = string.Empty;
                if (sort1>0)
                {
                    width = std.Substring(0, sort1);
                }
                if (sort2<sort3)
                {
                    weight = std.Substring(sort2 + 1, sort3 - sort2-1);
                }

  

 

posted on 2015-11-10 16:49  落雪凝辰  阅读(373)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3