split characters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lyne_asp
    New Member
    • Aug 2006
    • 20

    split characters

    Hello Everybody

    Please help me to split the string, here is my code

    HiddenMembers.V alue += selectedItem.Va lue + ";" ;

    I want to split the value and pass it to array. PLease help me to split HIddenMembers.v alue into individual value


    Thanks
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by lyne_asp
    Hello Everybody

    Please help me to split the string, here is my code

    HiddenMembers.V alue += selectedItem.Va lue + ";" ;

    I want to split the value and pass it to array. PLease help me to split HIddenMembers.v alue into individual value


    Thanks
    Use the split () method of string

    Split () returns a String array containing the substrings in this instance that are delimited by elements of a specified Char array.

    here is the code in c# :

    Code:
     
    // string seperated by colons ';'
    	string info = HiddenMembers.Value.ToString();
     
    	string[ ] arInfo ;
     
    	// define which character is seperating fields
    	char[ ] splitter = {';'};
     
    	arInfo = info.Split(splitter);
     
    	for(int x = 0; x < arInfo.Length; x++)
    	{
    		Response.Write(arInfo[x] + "<br>");
    	}
    here is the code in VB :

    Code:
    Dim Info As StringInfo = HiddenMembers.Value.ToString()
    Dim arInfo As String() = Nothing
    arInfo = Info.Split(",")
    For x as Integer=0 To arInfo.Length-1 
    Response.Write(arInfo[x] & vbCrLf);
    Next
    Please check the code.....some modification may be needed....

    Comment

    • lyne_asp
      New Member
      • Aug 2006
      • 20

      #3
      Thank you very much, it works. I got the output that I want. My question is when I insert it to Database the output is

      21 07580
      21 15518
      21 19558
      21

      it should be
      21 07580
      21 15518
      21 19558

      Here is my Code:

      // string seperated by colons ';'
      string info = HiddenMembers.V alue.ToString() ;

      string[] arInfo;

      // define which character is seperating fields
      char[] splitter = { ';' };

      arInfo = info.Split(spli tter);

      for (int x = 0; x < arInfo.Length; x++)
      {
      //Response.Write( arInfo[x] + "<br>");

      OracleTransacti on myOracleTransac tionMembers = con.BeginTransa ction();

      OracleCommand myOracleCommand Members = con.CreateComma nd();
      myOracleCommand Members.Command Text =
      "INSERT INTO TEAM_MEMBERS (" +
      " ITEM_NO,MEMBER_ ID" +
      ") VALUES (" +
      " '" + Label1.Text + "'," +
      " '" + arInfo[x] + "'" +
      ")";

      myOracleCommand Members.Execute NonQuery();
      myOracleTransac tionMembers.Com mit();


      Thanks

      Comment

      • lyne_asp
        New Member
        • Aug 2006
        • 20

        #4
        Thank you very much, I got it.

        instead of
        for (int x = 0; x < arInfo.Length ; x++)

        I used
        for (int x = 0; x < arInfo.Length - 1; x++)


        Thanks

        Comment

        Working...