我有一个字符串,中间有“|”,把两个字符串分开,比如“abcd|efgh”,我用那个string的方法能得到“|”前后的两个字符串。比如分别得到“abcd” 和“efgh”

解决方案 »

  1.   

    str=".......";
    string[] array=str.Split('|')
      

  2.   

    如果中间有4个“ | ”, 用string.split('||||'),能把两个字符串分开吗?比如"abcd||||efgh", 想得到“abcd” 和 “efgh”
      

  3.   


    using System.Text.RegularExpressions;/// <summary>
            /// 分割字符串
            /// </summary>
            public string[] SplitString(string strContent, string strSplit)
            {
                if (strContent.IndexOf(strSplit) < 0)
                {
                    string[] tmp = { strContent };
                    return tmp;
                }
                return Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase);
            }使用 方法
    string[] strRes = SplitString("abcd||||efgh","||||");
      

  4.   

    string str  =  "abcd|efgh";
    string[] ss = str.Splid("|");
      

  5.   

    String str="abcd|efgh";
    String[] tmpStr=str.Split(new char(){'|'});
      

  6.   

    string str = "abcd|efgh";
    string[] arrStr = str.Split('|');
    arrStr[0];// = abcd
    arrStr[1];// = efgh
      

  7.   

    public static string[] Splid(string strContent,string strSplid)
    {
        if (strContent.IndexOf(strSplit) != -1) 
            return strContent.Split(strSplid);  
        else
            return {strContent};
    }