如何从数据库获取值并将其显示在换行符的标签中 [英] How to get the Values from database and show it in a label in a new line
本文介绍了如何从数据库获取值并将其显示在换行符的标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将值存储在数据库中,如
印度< 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 . . .
请将输出设置为相关标签.
有关的更多信息,
- Regex [跳过并选择 [
Please set the output to relevant label.
More information about,
- Regex[^]
- SkipWhile and Select[^]
试试这个:
Hi,
Try this:
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()); } }
祝一切顺利.
-AK
All the best.
-AK
这篇关于如何从数据库获取值并将其显示在换行符的标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Regex[^]
查看全文