picking out from a string and comparing

# Thread: picking out from a string and comparing

1. patty Guest

## picking out from a string and comparing

I have got a string i="021332413452" <BR>what I would like to do is take the first 2 numbers, skip the next two , <BR>take the next two and so on..<BR>eg from the above given string i: take 02 32 34 and then compare this three numbers <BR>if they are the same. The catch is this string "i" can be of any length<BR>how do i do it using vbscript in ASP

2. Andrew S Guest

## RE: picking out from a string and comparing

Lots of ways to do this.. maybe something like <BR><BR>equal = True<BR>for x = 1 to len(i) step 4<BR> a = mid(i, x, 2)<BR> b = mid(i, x + 4, 2)<BR> response.write a & "-" & b & "<BR>"<BR> if a &#060;&#062; b and b &#060;&#062; "" then <BR> equal = False<BR> exit for<BR> end if<BR>next<BR>response.write equal<BR>

3. patty Guest

## RE: picking out from a string and comparing

Ok, thx for the ans<BR>but how do i go about if I dont know the length of the string i and i got to compare with the every 4th "2 numbers".<BR>how do i do it<BR>waiting for the ans

4. Andrew S Guest

## RE: picking out from a string and comparing

that little piece of script will work regardless of the string length. <BR><BR>what do you mean by &#039;compare&#039;? I figured you were seeing if all the numbers were equal -- like: 004411440044 -- all three sets of 44s are matching, while in 004411440055, there&#039;s two 44s and a 55. in that script, it compares the first fourth pair with the second, then the second with the third, and so on, ultimately finding if they all are the same.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•