现在想 每次 都取 这些数据的 第一个数据  该如何写  程序  "1,11,111/2,22,222/3,33,333" 提前谢谢啦

解决方案 »

  1.   


                string str = "1,11,111/2,22,222/3,33,333";
                string str1 = str.Split('/')[0];
      

  2.   

    分隔字符串还可以这样写
    string[] array ="1,11,111/2,22,222/3,33,333".Split(new char[] {'/'},StringSplitOptions.RemoveEmptyEntries);
    array[0]也就是1,11,111
      

  3.   

    string str = "1,11,111/2,22,222/3,33,333";
    string[] str1 = str.Split('/');
    for(int i=0;i<str1.length;i++){
    具体输出的值的格式如  
    1 2 3
    11 22 33
    111 222 333
    这里可以输出你要的格式。
    }
      

  4.   

    楼上的不正确吧,你的输出格式应该是下面的样子吧:
    1,11,111
    2,22,222
    3,33,333
    正确的应该是:
    string str = "1,11,111/2,22,222/3,33,333";
    string[] sum = str.Split('/');
    string[] str1 = sum[0].Split(',');
    string[] str2 = sum[0].Split(',');
    string[] str3 = sum[0].Split(',');
    for(int i=0;i<str1.length;i++)
    {
      str1[i] + str2[i] + str3[i]
    }
      

  5.   

    我的具体代码如下 
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <style type ="text/css">
         td{ border :#e7e7e7 1px solid;}
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:GridView ID ="gvTs" runat ="server"  AutoGenerateColumns="false" GridLines="Both"
          >
        <Columns >
         <asp:TemplateField>
         <ItemTemplate>
          <table style ="border :#e7e7e7 1px solid;" >
          <tr><td>用户名</td><td colspan="2"><asp:TextBox ID ="txtName" runat ="server" Text ='<%#Eval("Name") %>'></asp:TextBox></td></tr>
           <tr>
            <td>
                   编号
                    </td>
                    <td>
                        尺码
                    </td>
                    <td>
                        颜色
                    </td>
           </tr>
            <tr>
            <td><%=No %></td>
            <td><%=Size %></td>
            <td><%=Colors %></td>
           </tr>
          </table>
         </ItemTemplate>
         </asp:TemplateField>
        </Columns>
        </asp:GridView>
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    using System.Collections.Generic;
    public partial class Default2 : System.Web.UI.Page
    {
        private string str = @"Data Source=DEEPXP\SQLEXPRESS;Initial Catalog=test1;User ID=sa; pwd=123";
        protected string No;
        protected string Size;
        protected string Colors;
        private int count;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gvTs.RowDataBound += gvTs_RowDataBound;
                gvTs.DataSource = getTs();
                gvTs.DataBind(); count = 1;
            }    }
        public List<Test> getTs()
        {
            string sql = string.Format("select * from ts");
            SqlConnection conn = new SqlConnection(str);
            SqlCommand comm = new SqlCommand(sql, conn);
            conn.Open();
            SqlDataReader dr = comm.ExecuteReader();
            List<Test> list = new List<Test>();
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Test ts = new Test();
                    ts.Name = dr["Name"].ToString();
                    ts.Content = dr["Content"].ToString();
                    list.Add(ts);
                } dr.Close();
            }
            conn.Close();
            return list;
        }
        protected void gvTs_RowDataBound(object sender, GridViewRowEventArgs e)
        {        if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Test ts = (Test)e.Row.DataItem;
                string content = ts.Content;
                //"1,11,111/2,22,222/3,33,333"            string[] str = content.Split('/');
                string[] a = new string[3];
                string[] b = new string[3];
                string[] c = new string[3];
                for (int i = 0; i < 3; i++)
                {
                    if (i == 0)
                    {
                        a = content.Split('/')[i].Split (',');                }
                    if (i == 1)
                    {
                        b = content.Split('/')[i].Split(',');
                    }
                    if (i == 2)
                    {
                        c = content.Split('/')[i].Split(',');
                    }
                }
                for (int i = 0; i < 3; i++)
                {
                    if (i == 0)
                    {
                        No = a[i];
                        Size = b[i];
                        Colors = c[i];                }
                    if (i == 1)
                    {
                        No = a[i];
                        Size = b[i];
                        Colors = c[i];
                    }
                    if (i == 2)
                    {
                        No = a[i];
                        Size = b[i];
                        Colors = c[i];
                    }
                }
            }
        }
    }
    public class Test
    {
        private string name;    public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string content;    public string Content
        {
            get { return content; }
            set { content = value; }
        }
    }
    输出的值为  
      
    用户名  
    编号  尺码  颜色  
    aaa bbb ccc 
     
    用户名  
    编号  尺码  颜色  
    aaa bbb ccc 
     
    实际我想要输入的为  
    用户名  
    编号  尺码  颜色  
    1 2 3 
    11 22 33
    111 222 333 
    用户名  
    编号  尺码  颜色  
    a b c
    aa bb cc
    aaa bbb ccc 
     请教  哪里有问题
      

  6.   

    有点笨,但可以实现string str = "1,11,111/2,22,222/3,33,333";
                string[] str1 = str.Split('/');
                string[,] str3=new string[3,3];
                string[] str2;
                StringBuilder label = new StringBuilder();
                for (int i = 0; i < str1.Length; i++)
                {
                    str2= str1[i].Split(',');
                    for (int j = 0; j < str2.Length; j++)
                    {
                        str3[i, j] = str2[j];  //先保存到二维数组
                    }
                }            
                for (int j = 0; j < 3; j++)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        label.Append(str3[i,j] + " ");  //行和列倒过来
                    }
                    label.Append("\r");
                }
                label1.Text = label.ToString();
      

  7.   

    意思就是 我数据库里面有这个一个  字段 的信息   "1,11,111/2,22,222/3,33,333"   读出后绑定到 GridView上面    格式为
    1 2 3 
    11 22 33
    111 222 333 现在绑定的仅仅是最后一条信息  请指教
      

  8.   

    多谢兄弟们了   GridView 双嵌套即可完成