验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

c#中怎么获取指定字符前的字符串

阅读:835 来源:乙速云 作者:代码code

c#中怎么获取指定字符前的字符串

      c#获取指定字符前的字符串

      问题描述

      Combobox的值为:100088|仓库编码1,如何将截取指定字符“|”前面的值100088呢??

      解决方案

      string[] arry = ComBoBox.Text.Trim().split('|');
      string 字符串 = arry[0];

      此处的字符串 已经拿到了 想要的值了。

      字符串=100088,这时候就可以用在你想要的地方了。

      c#去除字符串前后任意指定字符

              //调用
             MethodsCommon.TrimStr(",1234",",");
       
              /// 
              /// 去除字符串前后逗号
              /// 如:1,2,5, 变成 1,2,5
              ///,,,1,2,5, 变成 1,2,5
              ///,,,,,,, 变成""
              /// 
              /// 字符串
              /// 要去除的符号
              /// 
      public static string TrimStr(string str,string symbol)
              {
                 if (str == null || str == string.Empty)
                  {
                      return "";
                  }
                  int len = str.Length;
                  int st = 0;
                  char[] val = str.ToCharArray();
                  int i = 0;
                  while ((st < len) && (val[st] <= symbol))
                  {
                      i++;
                      st++;
                  }
                  while ((st < len) && (val[len - 1] <= symbol))
                  {
                      i++;
                      len--;
                  }
                  if (st == len)
                      return "";
                  return ((st > 0) || (len < str.Length)) ? str.Substring(st, str.Length - i) : str;
              }
    分享到:
    *特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
    相关文章
    {{ v.title }}
    {{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
    你可能感兴趣
    推荐阅读 更多>