重新排序逗号分隔句子到段落新 [英] Reorder comma seperated sentences into new paragraphs

查看:115
本文介绍了重新排序逗号分隔句子到段落新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以上是我上传到托管服务器拉数据从它使用的.asp code在一个HTML文件网站的数据库。传感器领域使用数据查找另一个表中可以包含多个值,但这些值是用逗号,分隔得。我在想,如果有一个数据库中或.asp页上有一个办法摆脱逗号,并在一个新的段落进行排序或,替换为< BR />每个句子之间

Above is a database that i am uploading to a hosting server to pull the data off of it to a website using .asp code in a HTML file. The sensors field gets the data using lookup from another table and can contain multiple values but these values are seperated using a comma ",". I was wondering if there was a way either within the database or on the .asp page to get rid of the comma and sort them in a new paragraph or replace the "," with "< br/ >" between each of the sentences

推荐答案

注意变化对原来的问题

原来的问题是参考ASP.NET。提供了一个完整的答案后,人们得知,提交人实际使用VBScript和经典ASP。最后更新这个答案体现了他的变化。

The original question was in reference to ASP.NET. After providing a thorough answer it transpired that the author was actually using VBScript and Classic ASP. The final update to this answer reflects his change.

我已经离开了我原来的答复,以防万一它可以帮助别人与最初问了同样的问题。

I have left my original answer just in case it helps someone else with the same issue as originally asked..

===================================

===================================

替换如果你想改变任何的顺序是不够的;即按字母顺序排列。

Replace won't be enough if you want to change any of the order; I.E alphabetically.

一个方法是将数据库字符串转换成列表,以逗号分割的。然后你可以输出这个列表中任何你想要的顺序。

One way would be to put the Database string into a list, splitting it at the comma. you can then output this list in any order you want.

例如

拆成一个列表

List<string> myList = yourSensorsString.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();

您就可以订购该但是您认为合适的。是这样的:

You can then order this however you see fit. Something like:

myList.Sort();

然后,只需通过每个项目,如 - 在myLbl也许是标签控制在页面上

foreach ( str in myList) {
    myLbl.Text += str + "<br />";
}

或者作为单独的段落,也许到文字

   foreach ( str in myList) {
        myLit.Text += "<p>" + str + "</p>";
    }

更新

这code上面的例子将放置在code-后面。你会从数据库中获取你的传感器字符串,然后把它,然后输出分割成列表中的HTML。没有必要让你的数据库来执行这种逻辑。
我也认为C#作为你从来没有说过你使用.NET的什么味道。

This code example above would be placed in your code-behind. You would get your sensors string from the database, and then split it into a list, then output to the HTML. No need to get your database to perform this sort of logic. I have also assumed C# as you never mentioned what flavour of .net you're using.

更新2

看你的小提琴后,我编辑稍微展现在那里你可以使用这种code的。也转换我的code到VB。希望这可以帮助。不能把更多的时间进入这个...... 小提琴是这里

After looking at your fiddle, i edited it slightly to show where you can use this sort of code. Also converted my code to VB. Hope this helps. Can't put any more time into this... Fiddle Is Here

更新3

原来的问题是ASP.NET - 事实证明,它实际上是经典ASP的OP是询问

The original question was for ASP.NET - as it turns out, it's actually Classic ASP the OP is asking about.

所以,拆分您的字符串是这样的:

So split your string like this:

myList=Split(rsLogbook("FieldName"), ",")
for each str in myList
    document.write(str & "<br />")
next

除此之外,我不能帮助任何进一步的 - 大量的时间花在这个:)

Other than that, I can't help any further - lot of time spent on this :)

这篇关于重新排序逗号分隔句子到段落新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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