合并两个字符串,然后按日期/时间进行排序PART#2 [英] Combine Two Strings and Order them by Date/Time PART# 2

查看:80
本文介绍了合并两个字符串,然后按日期/时间进行排序PART#2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这更多是问题的第二部分,从这里开始

This is more of a 2nd part of a question that start off here here

下面的代码很好用,但是我忘了一些东西,在日期/时间之前还有一个城市和州,例如:

The code below works great but I forgot something, there is also a City and State before the Date/Time, Example is:

strcountstf = "Chicago, IL,02/01/2012 3:05am###,Akron,OH,02/02/2012 7:05am###,Nashivlle,TN,02/05/2012 8:30pm###" 
strDateNTimes = "Buffalo,NY,03/01/2011 2:20am###,Las Vegas,NV,12/02/2012 8:00am###,Mount Vernon,IN,02/06/2012 6:45pm###"

下面是工作代码,但我忘了将City和State添加到strcountstf和strDateNTimes字符串中.现在,添加城市,州后,它将无法使用.

Below is the working code but I forgot to add the City and State into strcountstf and strDateNTimes string. Now when the City,State is added it does not work.

我想按日期/时间进行排序,但将城市,州显示为输出/结果...请再次帮助!! (我知道,我知道).

I would like to sort it by Date/Time but show the City,State as the Output/Result... please help AGAIN!! (I know, I know).

dim strcountstf 
dim strDateNTimes 
dim strCOMBO 
dim arrCOMBO 
dim strCOMBOSorted 
dim objSortedList 
dim i 

strcountstf = "02/01/2012 3:05am###,02/02/2012 7:05am###,02/05/2012 8:30pm###" 
strDateNTimes = "03/01/2011 2:20am###,02/02/2012 8:00am###,02/06/2012 6:45pm###" 

strCOMBO = strcountstf & "," & strDateNTimes 

arrCombo = Split(strCOMBO, ",") 

Set objSortedList = Server.CreateObject("System.Collections.SortedList") 

For i = LBound(arrCombo) To UBound(arrCombo) 
    Call objSortedList.Add(CDate(Replace(arrCombo(i), "###", "")), arrCombo(i)) 
Next 

strCOMBOSorted = "" 

For i = 0 To objSortedList.Count - 1 
    strCOMBOSorted = strCOMBOSorted & ", " & objSortedList.GetByIndex(i) 
Next 

strCOMBOSorted = Right(strCOMBOSorted, Len(strCOMBOSorted) - 2) 

Set objSortedList = Nothing 

Response.Write("<br>") 
Response.Write(strCOMBO) 
Response.Write("<br>") 
Response.Write(strCOMBOSorted) 

推荐答案

使用属性City,State和Time创建类,并提供一种返回形状良好的字符串并相应地填充它们的方法.

Make a Class with properties City, State and Time and a method to give a well shaped string back and fill them accordingly.

Class OmNomNom
    Public City, State
    Private time_, timeStr_
    Public Property Let [Time](t)
        timeStr_ = t
        time_ = cDate(replace(t, "###", ""))
    End Property
    Public Property Get [Time] ' as Date
        [Time] = time_
    End Property

    Public Function Regurgigate ' as String
        Regurgigate = join(array(City, State, timeStr_), ",")
    End Function

End Class

Set objSortedList = Server.CreateObject("System.Collections.SortedList")
For each chocolateCookie in array(strcountstf, trDateNTimes)
    for i = 0 to ubound(chocolateCookie) step 3
        Set myOmNomNom = new omNomNom
        myOmNomNom.City = chocolateCookie(i)
        myOmNomNom.State = chocolateCookie(i+1)
        myOmNomNom.Time = chocolateCookie(i+2)
        objSortedList.Add myOmNomNom.Time, myOmNomNom
    next
next

现在,您可以通过遍历排序列表(如前所述)来获取适当的字符串,并从Regurgigate方法中获取字符串:objSortedList.GetByIndex(i).Regurgigate()

Now you can get your proper strings by iterating through the sorted list (as you did before) and get the string from the Regurgigate method: objSortedList.GetByIndex(i).Regurgigate()

免责声明:未经测试的示例代码.

Disclaimer: Sample code is not tested.

这篇关于合并两个字符串,然后按日期/时间进行排序PART#2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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