Need help; how can I parse a sentence put in by a user,
using, String functions like Mid( ), Len( ), etc.
Ex: When will the new train be coming?
When
will
the
new
train
be
coming?
If you can help please do this thing is driving me nuts.
[tt]MID$()[/tt] is fairly easy to use. You tell it where you want it to start in the string and how many characters you want it to grab. The more difficult part is determining where you want to start and how many characters you want
A good approach for this is the [tt]INSTR()[/tt] function. It takes either 2 or 3 parameters. Unusually, it is the first parameter which is optional In its two-parameter form, INSTR takes a string and a substring (in that order), and returns the offset into the string of the first occurrance of the substring, or 0 if it does not occur. In its second form, a third parameter is added in front of the other two, which is where in the string to start looking. The following code outputs the offset of each space in the input string:
[tt] LINE INPUT "Enter a string: ", a$
x% = INSTR(a$, " " IF x% = 0 THEN
PRINT "There are no spaces in that string." ELSE
PRINT "Spaces are at locations:" DO
PRINT x%;
x% = INSTR(x% + 1, a$, " " LOOP WHILE x% <> 0 END IF
[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.