×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Parsing using Mid( )

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.

RE: Parsing using Mid( )

try this... just a quick outline

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( )

MID$() 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 INSTR() 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:

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close