Announcement

Collapse
No announcement yet.

ASP VB string extraction

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • ASP VB string extraction

    Right, all script gurus. Please help.

    I have an ASP page which basically just outputs some fields from a DB, one of these fields looks like the following

    Code:
    <CELLLIST>&NSATT=1&SATTR=Workshop&SATYP=SourceCode&SASIZ=80&SADES=Workshop
    Location&SACPY=0&SAOPT=&NCELS=2&CID##=59&PID##=162&SID##=1015&SNAME=Cell
    1015&SCRDT=2005/11/18&SCRBY=inside&SUPDT=2005/11/18&SUPBY=inside&SSTAT=P&SELCK=-1&SNTES=&SINDX=1&SDESC=brum
    2&SSRCT=C&SSRCS=\\?FastStatsBaseDirectory\insidetr\00000007\UserBase:
    \&SSRCE=\\?FastStatsBaseDirectory\insidetr\00000007\Export:\&SSRCP=&SSRCF=AUREEDTJ.CMB&SSRCD=brum 2&SDONE=-1&SCALC=-1&SURNP=00000059\00000162\00001015.sdf&SINC#=-1&SCODE=01015&STLOE=0&SBNTH=0&SBNIS=0&SBNNU=0&SBNDE=0&SBNLE=0&SBNL#=0&SBPTE=0&SBPT#=0&SBNSU
    =0&STNTH=0&STNIS=0&STNNU=0&STNDE=0&STNLE=0&STNL#=0&STNSU=0&STNSS=0&SFIXC=0&SUPCE=-1&SBASC=0&SPSTC=0&SFFMC=0&SCLE#=0&SCL##=0&SGBT#=5091&SNBT#=3096&SGTT#=
    3096&SNTT#=3096&SCOST=0&SBXTB=0,0,&STXTB=1995,0,&SA001=&CID##=59&PID##=162&SID##=1016&SNAME=Cell 1016&SCRDT=2005/11/18&SCRBY=inside&SUPDT=2005/11/18&SUPBY=inside&SSTAT=P&SELCK=-1&SNTES=&SINDX=2&SDESC=bourne&SSRCT=C&SSRCS=\\?FastStatsBaseDirectory\insidetr\00000007\
    UserBase:\&SSRCE=\\?FastStatsBaseDirectory\insidetr\00000007\Export:\&SSRCP=&SSRCF=FUATEDIS.CMB&SSRCD=bourne&SDONE=-1&SCALC=-1&SURNP=00000059\00000162\00001016.sdf&SINC#=-
    1&SCODE=01016&STLOE=0&SBNTH=0&SBNIS=0&SBNNU=0&SBNDE=0&SBNLE=0&SBNL#=0&SBPTE=0&SBPT#=0&SBNSU=0&STNTH=0&STNIS=0&STNNU=0&STNDE=0&STNLE=0&STNL#=0&STNSU=0&STNSS=
    0&SFIXC=0&SUPCE=-1&SBASC=0&SPSTC=0&SFFMC=0&SCLE#=0&SCL##=0&SGBT#=2839&SNBT#=1855&SGTT#=1855&SNTT#=1855&SCOST=0&SBXTB=0,0,&STXTB=0,984,&SA001=&NKATT=2&KATTR=Pack
    Code&KATYP=SourceCode&KASIZ=80&KADES=Mailing Pack Code Wk & Creative&KACPY=0&KAOPT=&KATTR=OutputFiles&KATYP=Text&KASIZ=255&KADES=Output Packs for Concatenating&KACPY=0&KAOPT=&NPAKS=2&CID##=59&PID##=162&SID##=1015&KID##=1252&KDESC=brum
     2&KCODE=01252&KPCNT=100&KLMT#=0&KOPCD=&KA001=&KA002=&CID##=59&PID##=162&SID##=1016&KID##=1253&KDESC=bourne&KCODE=01253&KPCNT=100&KLMT#=0&KOPCD=&KA001=&KA002=</CELLLIST>
    Right in and amongst that lot is some data I need to get out. SID##=xxxx (1015 and 1016 in this case). They are duplicated twice I only need them once.

    I could use

    Code:
    sTemp2 = (Recordset1.Fields.Item("JobResults").Value)
    
    	Pos1 = InStr(sTemp2, "SID##=")
    	Pos2 = InStr(Pos1+6, sTemp2, "SID##=")
    	sNew1 = Mid(stemp2, Pos1+6, 4)
    	sNew2 = Mid(stemp2, Pos2+6, 4)
    	response.Write(sNew1)
    	response.Write(sNew2)
    But the problem is it might me in more than twice, in fact SID##= could be in there 6+ times, so I need to use some sort of loop.

    Basically, search through the entire string and return me the 4 digits after SID##= (always 4 digits) but with no duplicates.

    Any ideas ?

    Hope this makes sense............it does to me anyway !!!

    Cheers
    Topper
    * Shamelessly mentioning "Don't forget to add reputation!"

  • #2
    Re: ASP VB string extraction

    This should work


    sTemp2 = (Recordset1.Fields.Item("JobResults").Value)

    FoundSid = True
    do while Foundsid = True
    FoundSID = False

    Pos1 = InStr(lastpos+6, sTemp2, "SID##=")
    if pos1 <> 0 then
    LastPos = pos1
    FoundSid= True
    sNew1 = Mid(stemp2, Pos1+6, 4)
    response.Write (sNew1)
    End if

    loop
    MCSE 2000\2003, A+
    00000001-00000011-00000011-00000111

    Comment


    • #3
      Re: ASP VB string extraction

      pcking999 you are the man..........you've come up trumps.....again.

      1 question, is it possible to get rid of the duplicates that it writes out ?

      Cheers
      Chris
      * Shamelessly mentioning "Don't forget to add reputation!"

      Comment


      • #4
        Re: ASP VB string extraction

        its writting duplicates? does it duplicated everything or just like the first and last ones? or do you mean that their are duplicate records in the file that you want to get rid of?

        EDIT: ah, i see you have duplicate entries in the db. i didn't see that part the first time. here this should do the trick.

        Dim SidList(1000)
        sTemp2 = (Recordset1.Fields.Item("JobResults").Value)

        FoundSid = True
        do while Foundsid = True
        FoundSID = False

        Pos1 = InStr(lastpos+6, sTemp2, "SID##=")
        if pos1 <> 0 then
        LastPos = pos1
        FoundSid= True
        sNew1 = Mid(stemp2, Pos1+6, 4)

        AddToList = True
        for i = 0 to counter
        if sidlist(i) = snew1 then
        AddtoList = False
        end if
        next

        if AddtoList = true then
        sidlist(i) = snew1
        counter = counter + 1
        response.Write(sNew1)
        end if
        End if

        loop
        Last edited by pcking999; 2nd December 2005, 15:20.
        MCSE 2000\2003, A+
        00000001-00000011-00000011-00000111

        Comment

        Working...
        X