brake up a string

  • Thread starter Christopher Brandsdal
  • Start date
C

Christopher Brandsdal

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
 
T

Tom B

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
 
C

Christopher Brandsdal

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? :)
 
T

Tom B

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
 
C

Christopher Brandsdal

Thanks! that worked!

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

:)

Christopher
 
T

Tom B

Yes, sorry.

Christopher Brandsdal said:
Thanks! that worked!

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

:)

Christopher
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,099
Messages
2,570,626
Members
47,237
Latest member
David123

Latest Threads

Top