Jump to content

Help with StringInStr and stuff


i542
 Share

Recommended Posts

Howdie,

I have this piece of code

Func _Talk($Input)
    Switch $Input
        Case "Hi", "Greetings"
            Return "Hello"
    EndSwitch
EndFunc
(Shorten).

So, now, if I run it (with inputbox & stuff, of course) it only responds on "Hi", not on "Hi.", "Hi?" or "Hi!". I know it could be made by using If and StringInStr but that is really long and unreadable. Switch (or Select) is simple and compact :)

I would very appreciate your solution/response/howto (if you have it, of course).

What Doesn't Work

I tried this but they won't work:

Func _Talk($Input)
    Switch $Input
        Case "Hi" OR "Greetings"
            Return "Hello"
    EndSwitch
EndFunc
That would always return "Hello", eg. "What's Up?" "Hello"

Thanks! :P

i542

I can do signature me.

Link to comment
Share on other sites

Still involves a messy "String" function, which I'm guessing you want to stay away from. But this is how I might do it.

Msgbox(1,"",_Talk(InputBox("","Hello")))


Func _Talk($Input)
    Select
        Case StringRegExp($Input,"Hi?") OR StringRegExp($Input,"Greetings?")
            Return "Hello"
    EndSelect
    Return "Fine, don't say Hi."
EndFunc
Link to comment
Share on other sites

Still involves a messy "String" function, which I'm guessing you want to stay away from. But this is how I might do it.

Msgbox(1,"",_Talk(InputBox("","Hello")))


Func _Talk($Input)
    Select
        Case StringRegExp($Input,"Hi?") OR StringRegExp($Input,"Greetings?")
            Return "Hello"
    EndSelect
    Return "Fine, don't say Hi."
EndFunc
Yes, I tried it, but it won't work :). Thanks on answer. Edited by i542

I can do signature me.

Link to comment
Share on other sites

See if this works:

Msgbox(1,"",_Talk(InputBox("","Hello")))


Func _Talk($Input)
    Select
        Case StringRegExp($Input,"^Hi[.!?]?$") OR StringRegExp($Input,"^Greetings[.!?]?$")
            Return "Hello"
    EndSelect
    Return "Fine, don't say Hi."
EndFunc
Yes that's the one! Thanks! :)

I can do signature me.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...