最短租期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg   截取:跟|之间的字符  c#并将值赋给指定的文本框中

解决方案 »

  1.   

    提供个思路:用string的split方法,可以先split‘|’,然后split‘:’;也可以直接split‘|’和‘:’,然后取奇数下标的值。
      

  2.   

    string str = "最短租期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg";
    string[] array = str.Split('|');
    txt.Text=array[0].toString();
    txt.Text=array[1].toString();
    txt.Text=array[2].toString();
    txt.Text=array[3].toString();
    txt.Text=array[4].toString();
      

  3.   

      string _ValueText = "半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg ";            string[] _Value = _ValueText.Split(new char[]{':'},StringSplitOptions.RemoveEmptyEntries);            for (int i = 0; i != _Value.Length; i++)
                {
                    string[] _Text = _Value[i].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (_Text.Length == 2)
                    {
                        MessageBox.Show(_Text[0], _Text[1]);
                    }
                }
      

  4.   

    string str = "最短租期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg";
    string[] array = str.Split('|');
    txt.Text=array[0].toString();
    txt.Text=array[1].toString();
    txt.Text=array[2].toString();
    txt.Text=array[3].toString();
    txt.Text=array[4].toString();
      

  5.   

    string[] strs = "你的字符串".split('|');
      

  6.   

    测试过的代码:string _ValueText = "工期:半年|付款要求:年付|押金要求:两月租金|入住时间:agew|看房时间:gaweg ";
    char[] sep ={ '|',':' };
    string[] val = _ValueText.Split(sep);
    for (int i = 0; i < val.Length; i++)
    {
            if (i % 2 == 1) MessageBox.Show(val[i]);
    }
      

  7.   

     string[] array = str.Split(new char[2]{':','|'});
            for (int i = 0; i < array.Length; i++)
            {
                switch (array[i].ToString())
                {
                    case "最短租期": 
                        for (int j = 0; j <rblShortLease.Items.Count; j++)
                        {
                            if (rblShortLease.Items[j].Text == array[i + 1].ToString())
                                rblShortLease.Items[j].Selected = true;
                        }; break;
                    case "付款要求":
                        for (int j = 0; j < rblPay.Items.Count; j++)
                        {
                            if (rblPay.Items[j].Text == array[i + 1].ToString())
                                rblPay.Items[j].Selected = true;
                        }; break;
                    case "押金要求":
                        for (int j = 0; j < rblForegift.Items.Count; j++)
                        {
                            if (rblForegift.Items[j].Text == array[i + 1].ToString())
                                rblForegift.Items[j].Selected = true;
                        }; break;
                    case "入住时间": txtLiveDate.Text = array[i + 1].ToString(); break;
                    case "看房时间": txtLookDate.Text = array[i + 1].ToString(); break;
                }
            }