Purchase Solution

Explaining Substring Commands

Not what you're looking for?

Ask Custom Question

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

Purchase this Solution

Solution Summary

The substring commands are explained.

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 ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

C++ Operators

This quiz tests a student's knowledge about C++ operators.