strings string and strings

# Thread: strings string and strings

1. patty Guest

## strings string and strings

hi all<BR>I have a string of numbers like this "129012451267"<BR>here I have to check if the first two numbers of every four numbers are equal or not, In this case they are. i.e, 12<BR>so I need the o/p as that number(here its 12)<BR><BR>In another string like "129300341287" here they are not, <BR>i.e, we have 12 00 12, where we have one another number(12) and 00, So I need the o/p as the major number. In this case its 12<BR><BR>In another string like "129345346587" here we have three different numbers 12 45 65, so I need the o/p XX<BR><BR>One another thing is the string can be of any 4 digit length , like 4,8,12,16 ....digits long.<BR><BR>Its like U can see it and tell the answer, but how do i code it in ASP using VBScript<BR><BR>hope to hear from u <BR>thx<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

So what do you do with<BR><BR>"1200340012113411"<BR>???<BR><BR>Here, 12 and 34 each appear twice. So which one "wins"???<BR><BR>When you say you need the output XX for the three different numbers, do you mean *LITERALLY* "XX" ??<BR><BR>Any other boundary conditions you didn&#039;t tell us about? Suppose we get<BR><BR>120034005600121134111299<BR><BR>12 is there 3 times<BR>34 twice<BR>56 once<BR><BR>Does 12 "win" in that case?<BR><BR>By the way, if you can type in a string like "129345346587" how come you can&#039;t type in "output"?? Or "you"?<BR><BR>(C...1 uv my pp&#039;s w/ ng pstgs.)<BR><BR>

3. patty Guest

So what do you do with "1200340012113411" ??? <BR>Here, 12 and 34 each appear twice. So which one "wins"??? <BR>-)D8 is the output<BR><BR>When you say you need the output XX for the three different numbers, do you mean *LITERALLY* "XX" ?? <BR>-)I actually need D8<BR><BR>Any other boundary conditions you didn&#039;t tell us about? Suppose we get 120034005600121134111299 12 is there 3 times 34 twice <BR>56 once <BR>Does 12 "win" in that case? <BR>-) In this case the output is D8 because 12 34 and 56 are all different.<BR>It can be any one number(12 OR 34 OR 56) and 00 only, then the ans is that number , beccause its greater than 00<BR><BR>I&#039;ll give it to u as the need is<BR>- If the string comes from only one row, the header byte(the first 2 chars of every four chars is the header byte)<BR> is the upper byte(the two chars we need) of the chars<BR>- IF the string comes from only one row other than row 00, but also has chars only from row 00, the header byte is the upper byte of the chars from the non 00 row<BR>- Else its D8<BR>eg:0023 1234 0012<BR>here in 0023, 00 is the header byte of 0023<BR>12 is the header byte of 1234<BR>00 is the header byte of 0012<BR>so our output should be 12 because its the header byte of the non zero row(every 4 numbers correspond to one row, we have 3 entries, 2 from 00 row and one from 12 row)<BR>hope this helps

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Whew...weird...

Okay...I&#039;ll try...<BR><BR>&#060;%<BR>Function GetFlag( str ) &#039; str is your funny string<BR>&nbsp; &nbsp; If Len(str) &#060; 4 OR ( Len(str) MOD 4 ) &#060;&#062; 0 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; bad length for string!<BR>&nbsp; &nbsp; &nbsp; &nbsp; GetFlag = "D8"<BR>&nbsp; &nbsp; &nbsp; &nbsp; Exit Function<BR>&nbsp; &nbsp; End If<BR><BR>&nbsp; &nbsp; result = 0 &#039; initialize result<BR>&nbsp; &nbsp; For n = 1 To Len(str) Step 4 &#039; 4 characters at at time...<BR>&nbsp; &nbsp; &nbsp; &nbsp; curnum = CInt( Mid( str, n, 2 ) ) &#039; but get just 2 digits as a number<BR>&nbsp; &nbsp; &nbsp; &nbsp; If curnum &#062; 0 Then &#039; replace 0 result...<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If result &#062; 0 Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039; two non-zero values...error? D8 is code?<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetFlag = "D8"<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit Function<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039; if here, this is the first num &#062; 0<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = curnum<BR>&nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; Next<BR>&nbsp; &nbsp; GetFlag = Right( "00" & result, 2 )<BR>End Function<BR>%&#062;<BR><BR>

5. patty Guest

## weird, I know..

bill thx for the reply ,But I haven&#039;t got my solution<BR>but I always get the ans as D8....<BR><BR>even If I use the string "1234 1299 1265"(given spaces for easyness)<BR>I should have got 12 here, becos 12 is the only row here..<BR><BR>if I use "1234 0099 1265"<BR>I should again get 12 , becos it is from only one row(12) and row 00 . so I should get the output as 12 because its the upper header of the non zero row(every 4 numbers correspond to one row)<BR><BR>if I use "123460994365<BR>then I should get D8 because its from more than one row and therz no 00 row

6. patty Guest

## Bill wilkinson do u know the final solution?

Bill wilkinson do u know the final solution?

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Oh...you didn't give that example!

Easy to fix:<BR><BR>Just change this line:<BR>&nbsp; &nbsp; &nbsp; &nbsp; If result &#062; 0 Then <BR>to this: <BR>&nbsp; &nbsp; &nbsp; &nbsp; If result &#062; 0 AND result &#060;&#062; curnum Then <BR><BR>See why? Before, it rejected on finding a non-zero number if it already had found *any* non-zero number. Now it rejects only if the non-zero number does not match the one it had previously found.<BR><BR>Dirt simple. I bet you could have found this one if you&#039;d looked at my logic closer.<BR><BR>

#### Posting Permissions

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