how to use the text.split with comma

Last post 11-05-2009 10:18 AM by MadhavRao. 2 replies.

Sort Posts:

  • how to use the text.split with comma

    11-05-2009, 9:43 AM
    • Member
      20 point Member
    • aduhperf
    • Member since 03-18-2009, 12:21 PM
    • Posts 52

    Please how can i use the .Split properly. Right now it is not givin me the result i want. i am using  LiteralTitle.Text.Split(',') to split records inserted in one column separated by comma. but the problem i am  having is that the unsplitted records shows first before the slipted records. How can i hide the unsplitted records so it dosnt show at all. for example, this is what is showing

    1Arsenal, 2Chelsea, 3Bolton

    1Arsenal
    2Chelsea
    3Bolton

    How can i make sure that only this shows
    1Arsenal
    2Chelsea
    3Bolton


    Below is my code section:


     StringBuilder sb = new StringBuilder();
            foreach (var s in aways)
            {
                sb.AppendLine(s.Title.ToString());
            }
            LiteralTitle.Text = sb.ToString();
            
            foreach (string s in LiteralTitle.Text.Split(','))
                
            {
                LiteralTitle.Text += s + "<br />";
                
            }



    Thanks.

  • Re: how to use the text.split with comma

    11-05-2009, 10:17 AM
    • Member
      137 point Member
    • JuKiM
    • Member since 08-13-2007, 11:21 AM
    • Posts 124

    Hi,

    You are appending the splitted tags to "LiteralTitle.Text", Have you tried to append in a new string, and then put it to the LiteralTitle.Text?

    auxString="";

    foreach (string s in LiteralTitle.Text.Split(','))

    {

         auxString += s + "< /br>";

    }

    LiteralTitle.text=auxString;

    PitiPim
  • Re: how to use the text.split with comma

    11-05-2009, 10:18 AM
    Answer
    • Member
      246 point Member
    • MadhavRao
    • Member since 06-06-2004, 9:12 PM
    • Mumbai
    • Posts 48

    Change your code to 

    StringBuilder sb = new StringBuilder();
            foreach (var s in aways)
            {
                sb.AppendLine(s.Title.ToString());
            }
            LiteralTitle.Text = sb.ToString();
            
            foreach (string s in LiteralTitle.Text.Split(','))
                
            {
                LiteralTitle.Text += s + "<br />";
                
            }


    StringBuilder sb = new StringBuilder();
            foreach (var s in aways)
            {
                sb.AppendLine(s.Title.ToString());
            }
            var temp = sb.ToString();
            LiteralTitle.Text = "";
            foreach (string s in temp.Split(','))            
            {
                LiteralTitle.Text += s + "<br />";
                
            }


Page 1 of 1 (3 items)