0

Can someone please help me out? My code for splitting the strings is working however, i still need to use the splitted string my page. How can i achieve this? Here's my current code

    private void SplitStrings()
    {
        List<string> listvalues = new List<string>();
        listvalues = (List<string>)Session["mylist"];
        string[] strvalues = listvalues.ToArray();

        if (listvalues != null)
        {
            foreach (string strElement in listvalues)
            { 
                string[] prods = strElement.ToString().Split("|".ToCharArray());
                string prodName = prods[0].ToString();
                Response.Write(prodName);
            }
        }
    }

link text

how can i replace the response.write with any label or literal? when i tried to use a literal on the code it displays one single string not all of the strings that's been splitted.

any ideas?

1
  • I'm not sure I can tell what problem you're seeing - can you explain in more detail what output you want to see?
    – Dan Puzey
    Jun 14, 2010 at 9:18

3 Answers 3

0

Instead of just assigning the value use the concatenation operator to get all the strings. If your label name is label1 then something like

label1.Text += prods[0].ToString(); 

will be enough.

0

If you are only seeing one prodName in the label then it sounds to me like you are doing something like this when assigning the value of the label:

label1.text = prodName

This will simply set the value of label1 to prodName. In fact you need to contatenate the label and do something similar to this:

label1.text += prodName

This essentially says, take the value of label1 and add prodName to the end. The first statement was saying take the value of label1 and set it to prodName

0
0

Just cycle over the string array:

foreach(string s in prods)
{
  response.write(s);
}

BTW this strElement.ToString().Split("|".ToCharArray());

can be replaced by this strElement.Split('|');

because strElement is already a string and to specify a char you have to use single quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.