如何从数据库获取值并将其显示在换行符的标签中 [英] How to get the Values from database and show it in a label in a new line

查看:101
本文介绍了如何从数据库获取值并将其显示在换行符的标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我将值存储在数据库中,如

印度< br/>马来西亚< br/>新加坡

当我从数据库中获取值时,需要在类似这种结构的标签中显示这些值

印度

马来西亚

新加坡

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

推荐答案

以下代码可能会帮助您,

following code might help you,

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 . . .




请将输出设置为相关标签.

有关的更多信息,

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆