brake up a string

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

    brake up a string

    Hi!

    I have a string I have to break up in several strings.

    THe string looks like this:

    39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna

    The Syntax is NUMBER-TEXT,

    I wan't to break up the string like this:

    39 Fagleder
    38 Eier
    42 Avdelingsleder
    37 Etelleranna


    I have tried to use For Next.

    Is it better if the Syntax is: NUMBER,TEXT,

    ??

    Thanks!
    Christopher Brandsdal



  • Tom B

    #2
    Re: brake up a string

    you can use the split function to create an array.

    Dim TheString
    TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"
    TheString=Repla ce(TheString,"-"," ") 'Replaces the dashes with spaces

    Dim TheArray
    TheArray=Split( TheString,",") 'Splits on the comma

    Dim iLoop
    For iLoop=0 to UBound(TheArray )-1
    Response.write "<LI>" & TheArray(iLoop) & "</LI>"
    Next


    "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
    news:%23dzN5hEf DHA.368@TK2MSFT NGP12.phx.gbl.. .[color=blue]
    > Hi!
    >
    > I have a string I have to break up in several strings.
    >
    > THe string looks like this:
    >
    > 39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna
    >
    > The Syntax is NUMBER-TEXT,
    >
    > I wan't to break up the string like this:
    >
    > 39 Fagleder
    > 38 Eier
    > 42 Avdelingsleder
    > 37 Etelleranna
    >
    >
    > I have tried to use For Next.
    >
    > Is it better if the Syntax is: NUMBER,TEXT,
    >
    > ??
    >
    > Thanks!
    > Christopher Brandsdal
    >
    >
    >[/color]


    Comment

    • Christopher Brandsdal

      #3
      Re: brake up a string

      Thanks for fast respons!

      But if I want to display the text?

      Is the any way to cut out the numeric part?

      because I want to store TheArray(iLoop) in a database and display ONLY the
      Text on the page...

      Is this possible? :)


      "Tom B" <shuckle@NOSPAM hotmail.com> skrev i melding
      news:eApbIqEfDH A.988@TK2MSFTNG P10.phx.gbl...[color=blue]
      > you can use the split function to create an array.
      >
      > Dim TheString
      > TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"
      > TheString=Repla ce(TheString,"-"," ") 'Replaces the dashes with spaces
      >
      > Dim TheArray
      > TheArray=Split( TheString,",") 'Splits on the comma
      >
      > Dim iLoop
      > For iLoop=0 to UBound(TheArray )-1
      > Response.write "<LI>" & TheArray(iLoop) & "</LI>"
      > Next
      >
      >
      > "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
      > news:%23dzN5hEf DHA.368@TK2MSFT NGP12.phx.gbl.. .[color=green]
      > > Hi!
      > >
      > > I have a string I have to break up in several strings.
      > >
      > > THe string looks like this:
      > >
      > > 39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna
      > >
      > > The Syntax is NUMBER-TEXT,
      > >
      > > I wan't to break up the string like this:
      > >
      > > 39 Fagleder
      > > 38 Eier
      > > 42 Avdelingsleder
      > > 37 Etelleranna
      > >
      > >
      > > I have tried to use For Next.
      > >
      > > Is it better if the Syntax is: NUMBER,TEXT,
      > >
      > > ??
      > >
      > > Thanks!
      > > Christopher Brandsdal
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Tom B

        #4
        Re: brake up a string

        Sure, don't do the Replace part, so each of your array elements contains
        "##-sssss"
        Where # is a number and is followed by a dash. You can then do another
        split.

        Dim TheString
        TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"

        Dim TheArray
        TheArray=Split( TheString,",") 'Splits on the comma

        Dim iLoop
        Dim AnotherArray

        For iLoop=0 to UBound(TheArray )-1
        Response.write "<LI>" & TheArray(iLoop) & "</LI>"

        AnotherArray=Sp lit(TheArray,"-")
        'At this point AnotherArray(0) should contain the number part and
        AnotherArray(1) should contain the text
        Response.Write "<LI>" & AnotherArray(1) & "</LI>"

        Next




        "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
        news:uUInZtEfDH A.2352@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Thanks for fast respons!
        >
        > But if I want to display the text?
        >
        > Is the any way to cut out the numeric part?
        >
        > because I want to store TheArray(iLoop) in a database and display ONLY the
        > Text on the page...
        >
        > Is this possible? :)
        >
        >
        > "Tom B" <shuckle@NOSPAM hotmail.com> skrev i melding
        > news:eApbIqEfDH A.988@TK2MSFTNG P10.phx.gbl...[color=green]
        > > you can use the split function to create an array.
        > >
        > > Dim TheString
        > > TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"
        > > TheString=Repla ce(TheString,"-"," ") 'Replaces the dashes with spaces
        > >
        > > Dim TheArray
        > > TheArray=Split( TheString,",") 'Splits on the comma
        > >
        > > Dim iLoop
        > > For iLoop=0 to UBound(TheArray )-1
        > > Response.write "<LI>" & TheArray(iLoop) & "</LI>"
        > > Next
        > >
        > >
        > > "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
        > > news:%23dzN5hEf DHA.368@TK2MSFT NGP12.phx.gbl.. .[color=darkred]
        > > > Hi!
        > > >
        > > > I have a string I have to break up in several strings.
        > > >
        > > > THe string looks like this:
        > > >
        > > > 39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna
        > > >
        > > > The Syntax is NUMBER-TEXT,
        > > >
        > > > I wan't to break up the string like this:
        > > >
        > > > 39 Fagleder
        > > > 38 Eier
        > > > 42 Avdelingsleder
        > > > 37 Etelleranna
        > > >
        > > >
        > > > I have tried to use For Next.
        > > >
        > > > Is it better if the Syntax is: NUMBER,TEXT,
        > > >
        > > > ??
        > > >
        > > > Thanks!
        > > > Christopher Brandsdal
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Christopher Brandsdal

          #5
          Re: brake up a string

          Thanks! that worked!

          I just had to change AnotherArray=Sp lit(TheArray,"-") to
          AnotherArray=Sp lit(TheArray(iL oop),"-")

          :)

          Christopher


          "Tom B" <shuckle@hotmai l.com> skrev i melding
          news:e34BdFFfDH A.576@tk2msftng p13.phx.gbl...[color=blue]
          > Sure, don't do the Replace part, so each of your array elements contains
          > "##-sssss"
          > Where # is a number and is followed by a dash. You can then do another
          > split.
          >
          > Dim TheString
          > TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"
          >
          > Dim TheArray
          > TheArray=Split( TheString,",") 'Splits on the comma
          >
          > Dim iLoop
          > Dim AnotherArray
          >
          > For iLoop=0 to UBound(TheArray )-1
          > Response.write "<LI>" & TheArray(iLoop) & "</LI>"
          >
          > AnotherArray=Sp lit(TheArray,"-")
          > 'At this point AnotherArray(0) should contain the number part and
          > AnotherArray(1) should contain the text
          > Response.Write "<LI>" & AnotherArray(1) & "</LI>"
          >
          > Next
          >
          >
          >
          >
          > "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
          > news:uUInZtEfDH A.2352@TK2MSFTN GP09.phx.gbl...[color=green]
          > > Thanks for fast respons!
          > >
          > > But if I want to display the text?
          > >
          > > Is the any way to cut out the numeric part?
          > >
          > > because I want to store TheArray(iLoop) in a database and display ONLY[/color][/color]
          the[color=blue][color=green]
          > > Text on the page...
          > >
          > > Is this possible? :)
          > >
          > >
          > > "Tom B" <shuckle@NOSPAM hotmail.com> skrev i melding
          > > news:eApbIqEfDH A.988@TK2MSFTNG P10.phx.gbl...[color=darkred]
          > > > you can use the split function to create an array.
          > > >
          > > > Dim TheString
          > > > TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"
          > > > TheString=Repla ce(TheString,"-"," ") 'Replaces the dashes with spaces
          > > >
          > > > Dim TheArray
          > > > TheArray=Split( TheString,",") 'Splits on the comma
          > > >
          > > > Dim iLoop
          > > > For iLoop=0 to UBound(TheArray )-1
          > > > Response.write "<LI>" & TheArray(iLoop) & "</LI>"
          > > > Next
          > > >
          > > >
          > > > "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
          > > > news:%23dzN5hEf DHA.368@TK2MSFT NGP12.phx.gbl.. .
          > > > > Hi!
          > > > >
          > > > > I have a string I have to break up in several strings.
          > > > >
          > > > > THe string looks like this:
          > > > >
          > > > > 39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna
          > > > >
          > > > > The Syntax is NUMBER-TEXT,
          > > > >
          > > > > I wan't to break up the string like this:
          > > > >
          > > > > 39 Fagleder
          > > > > 38 Eier
          > > > > 42 Avdelingsleder
          > > > > 37 Etelleranna
          > > > >
          > > > >
          > > > > I have tried to use For Next.
          > > > >
          > > > > Is it better if the Syntax is: NUMBER,TEXT,
          > > > >
          > > > > ??
          > > > >
          > > > > Thanks!
          > > > > Christopher Brandsdal
          > > > >
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Tom B

            #6
            Re: brake up a string

            Yes, sorry.

            "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
            news:ON%236kuOf DHA.3616@TK2MSF TNGP11.phx.gbl. ..[color=blue]
            > Thanks! that worked!
            >
            > I just had to change AnotherArray=Sp lit(TheArray,"-") to
            > AnotherArray=Sp lit(TheArray(iL oop),"-")
            >
            > :)
            >
            > Christopher
            >
            >
            > "Tom B" <shuckle@hotmai l.com> skrev i melding
            > news:e34BdFFfDH A.576@tk2msftng p13.phx.gbl...[color=green]
            > > Sure, don't do the Replace part, so each of your array elements contains
            > > "##-sssss"
            > > Where # is a number and is followed by a dash. You can then do another
            > > split.
            > >
            > > Dim TheString
            > > TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"
            > >
            > > Dim TheArray
            > > TheArray=Split( TheString,",") 'Splits on the comma
            > >
            > > Dim iLoop
            > > Dim AnotherArray
            > >
            > > For iLoop=0 to UBound(TheArray )-1
            > > Response.write "<LI>" & TheArray(iLoop) & "</LI>"
            > >
            > > AnotherArray=Sp lit(TheArray,"-")
            > > 'At this point AnotherArray(0) should contain the number part and
            > > AnotherArray(1) should contain the text
            > > Response.Write "<LI>" & AnotherArray(1) & "</LI>"
            > >
            > > Next
            > >
            > >
            > >
            > >
            > > "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
            > > news:uUInZtEfDH A.2352@TK2MSFTN GP09.phx.gbl...[color=darkred]
            > > > Thanks for fast respons!
            > > >
            > > > But if I want to display the text?
            > > >
            > > > Is the any way to cut out the numeric part?
            > > >
            > > > because I want to store TheArray(iLoop) in a database and display ONLY[/color][/color]
            > the[color=green][color=darkred]
            > > > Text on the page...
            > > >
            > > > Is this possible? :)
            > > >
            > > >
            > > > "Tom B" <shuckle@NOSPAM hotmail.com> skrev i melding
            > > > news:eApbIqEfDH A.988@TK2MSFTNG P10.phx.gbl...
            > > > > you can use the split function to create an array.
            > > > >
            > > > > Dim TheString
            > > > > TheString="39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna"
            > > > > TheString=Repla ce(TheString,"-"," ") 'Replaces the dashes with[/color][/color][/color]
            spaces[color=blue][color=green][color=darkred]
            > > > >
            > > > > Dim TheArray
            > > > > TheArray=Split( TheString,",") 'Splits on the comma
            > > > >
            > > > > Dim iLoop
            > > > > For iLoop=0 to UBound(TheArray )-1
            > > > > Response.write "<LI>" & TheArray(iLoop) & "</LI>"
            > > > > Next
            > > > >
            > > > >
            > > > > "Christophe r Brandsdal" <christopherwb@ c2i.net> wrote in message
            > > > > news:%23dzN5hEf DHA.368@TK2MSFT NGP12.phx.gbl.. .
            > > > > > Hi!
            > > > > >
            > > > > > I have a string I have to break up in several strings.
            > > > > >
            > > > > > THe string looks like this:
            > > > > >
            > > > > > 39-Fagleder,38-Eier,42-Avdelingsleder, 37-Etelleranna
            > > > > >
            > > > > > The Syntax is NUMBER-TEXT,
            > > > > >
            > > > > > I wan't to break up the string like this:
            > > > > >
            > > > > > 39 Fagleder
            > > > > > 38 Eier
            > > > > > 42 Avdelingsleder
            > > > > > 37 Etelleranna
            > > > > >
            > > > > >
            > > > > > I have tried to use For Next.
            > > > > >
            > > > > > Is it better if the Syntax is: NUMBER,TEXT,
            > > > > >
            > > > > > ??
            > > > > >
            > > > > > Thanks!
            > > > > > Christopher Brandsdal
            > > > > >
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...