Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am storing the values in database like

India<br/> Malaysia<br/>Singapore<br/>

When I getting the values from Database, I need to display the values in a label like this structure

India

Malaysia

Singapore

How to do this one any help can be useful for me
Posted
Updated 14-May-12 16:52pm
v2
Comments
walterhevedeich 14-May-12 22:52pm    
Removed pre tag.

following code might help you,

C#
namespace ConsoleApplication24
{
    using System;
    using System.Linq;
    using System.Text.RegularExpressions;

    class Program
    {
        static void Main(string[] args)
        {
            string pattern = "<br/>";
            string sentence = "India<br/> Malaysia<br/>Singapore<br/>";
            string[] countries = Regex.Split(sentence, pattern);
            string labelOutput =string.Empty;
            labelOutput = string.Join(Environment.NewLine, countries.SkipWhile(country => string.IsNullOrEmpty(country)).Select(country=>country.Trim()));
            Console.WriteLine(labelOutput);
        }
    }
}


The output of the above program is as below,
India
Malaysia
Singapore

Press any key to continue . . .



Please set the output to relevant label.

More information about,

Hope it helps :)
 
Share this answer
 
Comments
Sandeep Mewara 15-May-12 2:53am    
full 5!
Mohammad A Rahman 15-May-12 3:05am    
Thank you very much Sandeep :) Though I have got 3 and 4 for this answer :)
Hi,

Try this:

C#
string sentence = "India<br/> Malaysia<br/>Singapore<br/>";
            string words = sentence.Replace("<br/>", " ");
            string[] word = words.Split(' '); //Now we have the words in array.
            foreach (string wrd in word) {
                if (wrd != "")
                {
                    Console.WriteLine(wrd.Trim());
                }
            }



All the best.
-AK
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900