Parse record, convert to session variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brandon

    Parse record, convert to session variables

    Greetings,

    I have a database with records that contain data like the following:

    "vendor" - "phone number" - "city", "state" "problem."

    For example:
    xyzcompany - 800-123-4567 - new york, ny tp.

    The line above is one record, the company names will differ (but are
    limited to a dozen), the format of the number will always be with a dash
    seperating the area code and number, the city and state will be in
    place, and the problem will be a two letter code followed by a period.

    I need to be able to parse that record into seperate session variables
    such as Session("vendor "), Session("area_c ode"), Session("number "), and
    on with the city, state, and problem.

    What is the best method to use in VBScript/ASP to break this record down
    into pieces?

    I appreciate any help you can give.

    Thanks,
    Brandon


    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Alan Howard

    #2
    Re: Parse record, convert to session variables

    You say the data below is a record - assuming that you are still able to
    address the individual fields, use something like:

    For Each objField In objRS.Fields

    Session (CStr(objField. Name)) = CStr(objField.V alue)

    Next

    - or are you asking how to split a single string??


    "Brandon" <bdreilingATmac .com> wrote in message
    news:%23038rsbT EHA.2324@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > Greetings,
    >
    > I have a database with records that contain data like the following:
    >
    > "vendor" - "phone number" - "city", "state" "problem."
    >
    > For example:
    > xyzcompany - 800-123-4567 - new york, ny tp.
    >
    > The line above is one record, the company names will differ (but are
    > limited to a dozen), the format of the number will always be with a dash
    > seperating the area code and number, the city and state will be in
    > place, and the problem will be a two letter code followed by a period.
    >
    > I need to be able to parse that record into seperate session variables
    > such as Session("vendor "), Session("area_c ode"), Session("number "), and
    > on with the city, state, and problem.
    >
    > What is the best method to use in VBScript/ASP to break this record down
    > into pieces?
    >
    > I appreciate any help you can give.
    >
    > Thanks,
    > Brandon
    >
    >
    > *** Sent via Devdex http://www.devdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]


    Comment

    • Dave Anderson

      #3
      Re: Parse record, convert to session variables

      Alan Howard wrote:[color=blue]
      >
      > For Each objField In objRS.Fields
      >
      > Session (CStr(objField. Name)) = CStr(objField.V alue)
      >
      > Next[/color]

      CStr is unnecessary with [Name]...
      Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.



      ....and possibly unwanted with [Value], depending on the data type.



      --
      Dave Anderson

      Unsolicited commercial email will be read at a cost of $500 per message. Use
      of this email address implies consent to these terms. Please do not contact
      me directly or ask me to contact you directly for assistance. If your
      question is worth asking, it's worth posting.


      Comment

      • Mark Schupp

        #4
        Re: Parse record, convert to session variables

        If your format and delimiters are fixed (unchanging) then

        a1 = split( strRecord, ",")
        a2 = split( a1(0), "-")
        a3 = split( a1(1), " ")

        vendor = a2(0)
        areacode = a2(1)
        phonenum = a2(2) & "-" a2(3)
        city = a2(4)
        state = a3(0)
        prob = a3(1)


        --
        Mark Schupp
        Head of Development
        Integrity eLearning



        "Brandon" <bdreilingATmac .com> wrote in message
        news:%23038rsbT EHA.2324@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        > Greetings,
        >
        > I have a database with records that contain data like the following:
        >
        > "vendor" - "phone number" - "city", "state" "problem."
        >
        > For example:
        > xyzcompany - 800-123-4567 - new york, ny tp.
        >
        > The line above is one record, the company names will differ (but are
        > limited to a dozen), the format of the number will always be with a dash
        > seperating the area code and number, the city and state will be in
        > place, and the problem will be a two letter code followed by a period.
        >
        > I need to be able to parse that record into seperate session variables
        > such as Session("vendor "), Session("area_c ode"), Session("number "), and
        > on with the city, state, and problem.
        >
        > What is the best method to use in VBScript/ASP to break this record down
        > into pieces?
        >
        > I appreciate any help you can give.
        >
        > Thanks,
        > Brandon
        >
        >
        > *** Sent via Devdex http://www.devdex.com ***
        > Don't just participate in USENET...get rewarded for it![/color]


        Comment

        • Alan Howard

          #5
          Re: Parse record, convert to session variables

          > CStr is unnecessary with [Name]...[color=blue]
          > ...and possibly unwanted with [Value], depending on the data type.[/color]

          Habit - easier than second-guessing variant sub-types.

          Alan

          "Dave Anderson" <GTSPXOESSGOQ@s pammotel.com> wrote in message
          news:OhC8JLjTEH A.904@TK2MSFTNG P12.phx.gbl...[color=blue]
          > Alan Howard wrote:[color=green]
          > >
          > > For Each objField In objRS.Fields
          > >
          > > Session (CStr(objField. Name)) = CStr(objField.V alue)
          > >
          > > Next[/color]
          >
          > CStr is unnecessary with [Name]...
          > http://msdn.microsoft.com/library/en.../mdproname.asp
          >
          >
          > ...and possibly unwanted with [Value], depending on the data type.
          >
          >
          >
          > --
          > Dave Anderson
          >
          > Unsolicited commercial email will be read at a cost of $500 per message.[/color]
          Use[color=blue]
          > of this email address implies consent to these terms. Please do not[/color]
          contact[color=blue]
          > me directly or ask me to contact you directly for assistance. If your
          > question is worth asking, it's worth posting.
          >
          >[/color]


          Comment

          • Brandon

            #6
            Re: Parse record, convert to session variables

            Thanks, that did the trick!

            Brandon
            _______________ _______________ ___________

            If your format and delimiters are fixed (unchanging) then

            a1 = split( strRecord, ",")
            a2 = split( a1(0), "-")
            a3 = split( a1(1), " ")

            vendor = a2(0)
            areacode = a2(1)
            phonenum = a2(2) & "-" a2(3)
            city = a2(4)
            state = a3(0)
            prob = a3(1)


            --
            Mark Schupp
            Head of Development
            Integrity eLearning


            *** Sent via Devdex http://www.devdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            Working...