x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 306

# Use values on either side of Split(String, "-") as for - to loop

Hi Experts,

I am working on code to break up a record containing weekintervals and/or weeknumber written as text strings separated thus: "6-8; 10-12; 14-15; 17; 19". I need to break it all up in separate records, in order to get a complete list of weeks like this: 6, 7, 8, 10, 11 12, 14, 15, 17, 19.

I so far succeed in splitting the ";" and "-", but fail to find a way of exploding each of the weekintervals (ex: 6-8) in separate lines.

The code I've written so far loks like this:

<%
a=Split("6-8; 10-12; 14-15; 17; 19", ";")
for each x in a

b=Split(x, "-")

for each y in b
response.write( y & "<br />")
next
next

%>

This gives the following result:

6
8
10
12
14
15
17
19

What i miss is to make it look like this:
6
7
8
10
11
12
14
15
17
19

Thanks for any suggestions

Best regards
MortenWB
0
MortenWB
• 2
1 Solution

Commented:
Hi Morten,
if you have a "-" then you have to use the two boundary values like:
`````` <%
a=Split("6-8; 10-12; 14-15; 17; 19", ";")
for each x in a
b=Split(x, "-")
if UBound(b) > 0 then
for y = b(0) To b(1)
response.write( y & "<br />")
next
else
response.write( b(0) & "<br />")
end if
next
%>
``````
HTH
Rainer
0

Commented:
<%
a=Split("6-8; 10-12; 14-15; 17; 19", ";")
for each x in a

b=Split(x, "-")

for i=b(lbound(b)) to b(ubound(b)+1)
response.write( i & "<br />")
next
next

%>

edit
Actually I just realised Rainer's solution is the same (just a bit different).
0

Author Commented:
Thank You both - Rainers solution went right in, while Cathals return a "Subscript out of range: '[number: 1]'" - error, wich I'm sure is caused by my lack of understanding.

But I am happy up and running again and settle for sharing the points.

Best regards

Morten B
0

Commented:
You need to remove the +1 bit
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 2
Tackle projects and never again get stuck behind a technical roadblock.