Words - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Words

PuzzlerPuzzler Posts: 208Member
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...

Comments

  • BASIC FriendBASIC Friend Posts: 354Member
    : 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...
    :
    [green]
    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.
    [/green]


  • billywm664billywm664 Posts: 176Member
    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...
    :


  • BASIC FriendBASIC Friend Posts: 354Member
    : : 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...
    : :
    : [green]
    : 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.
    : [/green]
    :
    :
    [red]
    Finally! I was having problems with my connection. Here it is:
    [
    ed]
    [code]
    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
    [/code]
    [red]
    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.

    [/red]



Sign In or Register to comment.