Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1681
Number of posts: 4770

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Words Posted by Puzzler on 19 Jun 2001 at 3:43 PM
Does anyone have a function that can pull a word out of a sentene. For exmaple:

a$ = word$("I love you", 2)
Print a$

This peice of code would return "love".

I know I could right it myself but I'm sure there already is one and i'm feeling lazy...

Report
Re: Words Posted by BASIC Friend on 19 Jun 2001 at 9:32 PM
: Does anyone have a function that can pull a word out of a sentene. For exmaple:
:
: a$ = word$("I love you", 2)
: Print a$
:
: This peice of code would return "love".
:
: I know I could right it myself but I'm sure there already is one and i'm feeling lazy...
:

I've written a function for parsing COMMAND$. I'll have to post it later. It'll do exactly what you asked, but it's simple code. You could write one yourself.



Report
Re: Commandline Parser Posted by BASIC Friend on 21 Jun 2001 at 7:37 PM
: : Does anyone have a function that can pull a word out of a sentene. For exmaple:
: :
: : a$ = word$("I love you", 2)
: : Print a$
: :
: : This peice of code would return "love".
: :
: : I know I could right it myself but I'm sure there already is one and i'm feeling lazy...
: :
:
: I've written a function for parsing COMMAND$. I'll have to post it later. It'll do exactly what you asked, but it's simple code. You could write one yourself.
:

:
:

Finally! I was having problems with my connection. Here it is:
[\red]
FUNCTION CMDLINE$ (x%)
    a$ = COMMAND$
    temp$ = ""
    count% = 1
    alen% = LEN(a$)
    FOR i% = 1 TO alen%
        m$ = MID$(a$, i%, 1)
        IF m$ = " " THEN count% = count% + 1
        IF m$ <> " " THEN
            IF x% = count% THEN temp$ = temp$ + m$
            END IF
    NEXT i%
    CMDLINE$ = UCASE$(temp$)
END FUNCTION


you'll need to modify it so that it takes a$ as an argument, and comment out the a$=COMMAND$.

I'll leave the rest to you.





Report
Re: Words Posted by billywm664 on 20 Jun 2001 at 6:19 AM
This sub should do it. You'll have to make it into a function if you want it to be. Just have the function return words(x), where x is the number of the word in the sentence you want to pull out.

DIM words(100) AS STRING
text$ = "I like chicken i like liver meow mix meow mix please deliver"
lastword = 1

FOR a = 1 TO 50
IF INSTR(lastword, text$, CHR$(32)) = 0 THEN
words(a) = MID$(text$, lastword, LEN(text$) - lastword + 1)
EXIT FOR
END IF
words(a) = MID$(text$, lastword, INSTR(lastword, text$, CHR$(32)) - lastword)
lastword = lastword + LEN(words(a)) + 1
NEXT a





: Does anyone have a function that can pull a word out of a sentene. For exmaple:
:
: a$ = word$("I love you", 2)
: Print a$
:
: This peice of code would return "love".
:
: I know I could right it myself but I'm sure there already is one and i'm feeling lazy...
:





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.