数据库中字符串
“优秀-10,良好-8,中等-5”怎样在页面中显示成
优秀  10
良好   8
中等   5
注:是在TextBox中显示,等级和分数在不同的TextBox里面。

解决方案 »

  1.   

    单单拆分的话不难吧,先spli(","),再split("-")
      

  2.   

    TextBox1.Text = stringA.split(',')[0].split('-')[0];//"优秀"
    TextBox1.Text = stringA.split(',')[0].split('-')[1];//"10"
      

  3.   

    TextBox1.Text = stringA.split(',')[0].split('-')[0];//"优秀"
    TextBox1.Text = stringA.split(',')[0].split('-')[1];//"10"
      

  4.   


    string a = "优秀-10,良好-8,中等-5";
    string[] tmp = a.Text.Split(',');
    this.textBox.text = tmp[0];
    this.textBox1.text = tmp[1];
    this.textBox2.text = tmp[2];
      

  5.   

    楼上真快 !!谢谢
    可从数据库中读的数据,不知道能拆分成多少条啊,就是不知道要用几个TextBox,要用动态的吗?
      

  6.   

    “优秀-10,良好-8,中等-5”.Replace("-", " ").Replace(",", "\n")
      

  7.   

     string str="优秀-10,良好-8,中等-5";
             string[] s = str.Split(new char[2] { '-', ',' });
             foreach (string a in s)
             {
                 Console.Write(a+"\r\n");
             }
    或用正则表达式
    http://topic.csdn.net/u/20090914/14/259b6335-996a-4ed3-a217-c863b391e418.html
      

  8.   

    要动态生成textbox id名称时规则一下就可以了....
      

  9.   

    string s=“优秀-10,良好-8,中等-5”;
    string strs[]=s.Split(',');
    for(int i=0;i<strs.length;i++)
    {
       (this.Form.FindControl("tb_grade"+i.ToString()) as TextBox).Text=strs[i].ToString().Split('-').GetValue(0).ToString();
       (this.Form.FindControl("tb_total"+i.Tostring()) as TextBox).Text=strs[i].ToString().Split('-').GetValue(1).ToString();
    }
      

  10.   

    干嘛非要用textbox,用其它控件不行?