Share
Explore BrainMass

Explaining Substring Commands

Point 5: Please explain VAL(MID\$(i\$, i, j))

Point 4: If I am going backwards down the string, then how do I pick up all the substrings since the string is read left to right?

This is in the context of the following solution:
1 i\$ = "37540" 'input string
2 FOR i = 1 TO LEN(i\$) 'loop from 1 to the length of the input string
3 FOR j = LEN(i\$) - i + 1 TO 1 STEP -1
4 'loop from the lenght from this point in the string to the end, down to 1
5 IF (VAL(MID\$(i\$, i, j)) MOD 3) = 0 THEN PRINT MID\$(i\$, i, j)
6 'using the modulo function, we check if the particular number is
'evenly divisible by 3
7 NEXT j 'end looping
8 NEXT i 'end looping

We could also check if a number is divisible by three by recursively summing its digits until it gets a single digit number. If that number is 3, 6 or 9, the number is divisible by 3.
That applies for the number 9 as well.
If the result is 9, then the original number was evenly divisible by 9

For example: 5469
5+4+6+9=24
2+4=6
therefore 5469 is evenly divisible by 3 or 5469 MOD 3 = 0

Solution Preview

Point 5:
----------------------------------------------------------------------
Val Function:
-------------
It Returns the numbers contained in a string as a numeric value of appropriate type.

Mid Function:
--------------
It Returns a string containing a specified number of characters from ...

\$2.19