brake up a string

Discussion in 'ASP General' started by Christopher Brandsdal, Sep 16, 2003.

  1. 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
     
    Christopher Brandsdal, Sep 16, 2003
    #1
    1. Advertising

  2. Christopher Brandsdal

    Tom B Guest

    you can use the split function to create an array.

    Dim TheString
    TheString="39-Fagleder,38-Eier,42-Avdelingsleder,37-Etelleranna"
    TheString=Replace(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


    "Christopher Brandsdal" <> wrote in message
    news:%...
    > 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, Sep 16, 2003
    #2
    1. Advertising

  3. 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" <> skrev i melding
    news:...
    > you can use the split function to create an array.
    >
    > Dim TheString
    > TheString="39-Fagleder,38-Eier,42-Avdelingsleder,37-Etelleranna"
    > TheString=Replace(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
    >
    >
    > "Christopher Brandsdal" <> wrote in message
    > news:%...
    > > 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
    > >
    > >
    > >

    >
    >
     
    Christopher Brandsdal, Sep 16, 2003
    #3
  4. Christopher Brandsdal

    Tom B Guest

    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=Split(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




    "Christopher Brandsdal" <> wrote in message
    news:...
    > 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" <> skrev i melding
    > news:...
    > > you can use the split function to create an array.
    > >
    > > Dim TheString
    > > TheString="39-Fagleder,38-Eier,42-Avdelingsleder,37-Etelleranna"
    > > TheString=Replace(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
    > >
    > >
    > > "Christopher Brandsdal" <> wrote in message
    > > news:%...
    > > > 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, Sep 16, 2003
    #4
  5. Thanks! that worked!

    I just had to change AnotherArray=Split(TheArray,"-") to
    AnotherArray=Split(TheArray(iLoop),"-")

    :)

    Christopher


    "Tom B" <> skrev i melding
    news:...
    > 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=Split(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
    >
    >
    >
    >
    > "Christopher Brandsdal" <> wrote in message
    > news:...
    > > 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" <> skrev i melding
    > > news:...
    > > > you can use the split function to create an array.
    > > >
    > > > Dim TheString
    > > > TheString="39-Fagleder,38-Eier,42-Avdelingsleder,37-Etelleranna"
    > > > TheString=Replace(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
    > > >
    > > >
    > > > "Christopher Brandsdal" <> wrote in message
    > > > news:%...
    > > > > 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
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Christopher Brandsdal, Sep 17, 2003
    #5
  6. Christopher Brandsdal

    Tom B Guest

    Yes, sorry.

    "Christopher Brandsdal" <> wrote in message
    news:ON%...
    > Thanks! that worked!
    >
    > I just had to change AnotherArray=Split(TheArray,"-") to
    > AnotherArray=Split(TheArray(iLoop),"-")
    >
    > :)
    >
    > Christopher
    >
    >
    > "Tom B" <> skrev i melding
    > news:...
    > > 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=Split(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
    > >
    > >
    > >
    > >
    > > "Christopher Brandsdal" <> wrote in message
    > > news:...
    > > > 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" <> skrev i melding
    > > > news:...
    > > > > you can use the split function to create an array.
    > > > >
    > > > > Dim TheString
    > > > > TheString="39-Fagleder,38-Eier,42-Avdelingsleder,37-Etelleranna"
    > > > > TheString=Replace(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
    > > > >
    > > > >
    > > > > "Christopher Brandsdal" <> wrote in message
    > > > > news:%...
    > > > > > 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, Sep 17, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edmilson

    How to brake a label server control ?

    Edmilson, Jul 4, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    393
    David Waz...
    Jul 5, 2003
  2. Mladen Adamovic
    Replies:
    0
    Views:
    777
    Mladen Adamovic
    Dec 4, 2003
  3. Mladen Adamovic
    Replies:
    3
    Views:
    14,782
    Mladen Adamovic
    Dec 5, 2003
  4. Matt
    Replies:
    3
    Views:
    556
    Tor Iver Wilhelmsen
    Sep 17, 2004
  5. Bruce Sam
    Replies:
    15
    Views:
    8,069
    John C. Bollinger
    Nov 19, 2004
Loading...

Share This Page