Parsing using Mid( )
Parsing using Mid( )
(OP)
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.
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.
RE: Parsing using Mid( )
String$="When will the new train be coming"
DIM Words(1 to 100) as String
DO
i=i+1
f$=MID$(String$,i,1)
if f$ <> " " then Word$=Word$+f$ else GOSUB Seperate_Word
LOOP UNTIL i = LEN(String$)
Seperate_Word:
Index=Index+1
Words(Index)=Word$
Word$=""
Return
RE: Parsing using Mid( )
A good approach for this is the INSTR() function. It takes either 2 or 3 parameters. Unusually, it is the first parameter which is optional
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
I'm sure you can adapt this to fit your needs.