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);
                }

  

原文地址:https://www.cnblogs.com/luoxueningchen/p/4953536.html