将逗号分隔的句子重新排序为新的段落 [英] Reorder comma separated sentences into new paragraphs

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

问题描述

数据库截图http://i45.tinypic.com/ib9zs2.jpg p>

上面是一个数据库,我上传到托管服务器,使用HTML文件中的.asp代码将数据提取到网站。传感器字段使用来自另一个表的查找获取数据,并且可以包含多个值,但是这些值使用逗号,分隔。我想知道是否有一种方式在数据库内或在.asp页面上删除逗号和排序他们在一个新的段落或替换,与每个句子之间的< br />

解决方案

注意更改原始问题



原来的问题是参考ASP.NET。在提供了一个彻底的答案后,发现作者实际上使用的是VBScript和Classic ASP。对这个答案的最后更新反映了他的变化。



我已离开我的原始答案,以防它帮助别人与原来问题相同的问题。



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



如果要更改任何订单,替换将不够;



一种方法是将数据库字符串放入列表,然后以逗号分割。



例如



可以分割成列表

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

然后,您可以订购,但您认为合适。像:

  myList.Sort(); 

然后简单地浏览每个项目,例如 - myLbl可能是标签控制您的页面

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

或者作为单独的段落,可能会成为 Literal

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

更新

上面的代码示例将放在代码隐藏中。您将从数据库中获取传感器字符串,然后将其拆分为列表,然后输出到HTML。无需让您的数据库执行这种逻辑。
我也假设C#,因为你从来没有提到你使用的.net的什么风味。



更新2

>

看了你的小提琴之后,我稍微编辑了一下,以显示你可以在哪里使用这种代码。还将我的代码转换为VB。希望这可以帮助。不能再将更多时间投入到此... 小提琴在这里



更新3



原来的问题是ASP.NET - 事实证明,

 <$ c $ 

c> myList = Split(rsLogbook(FieldName),,)
对于myList中的每个str
document.write(str&< br />)
next

除此之外,我不能帮助任何进一步的 -


database screenshot http://i45.tinypic.com/ib9zs2.jpg

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

解决方案

NOTE CHANGE TO ORIGINAL QUESTION

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.

For example.

to Split into a list

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

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

myList.Sort();

Then simply go through each of the items, like - where myLbl is perhaps a label control on your page

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

Or as separate paragraphs, maybe into a Literal

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

Update

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.

Update 2

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

Update 3

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天全站免登陆