Jump to content

Serach for word in string?


pgus
 Share

Recommended Posts

How do I search for specific word in string?

Can someone give me example?

Another method, is to use StringRegExp() which will only match complete words.

StringRegExp offers more flexibility than StringInStr but is slower.

Which method you use depends on exactly what you require to find.

#include <array.au3>
Dim $result = StringRegExp("I love rock n roll, put another dime in the juke-box baby.", "\banother\b")
    If $result = 0 Then
        MsgBox(0,"","Not Found")
    Else
        MsgBox(0,"","Found")
    EndIF

    ;More examples for checking if one of several words is present demonstating different StringRegExp options 
    $result1 = StringRegExp("I love rock n roll, put another dime in the juke-box baby.", "\b(the|Jazz|juke|box|n)\b",1)
    _ArrayDisplay($result1,"Return form StringRegExp() with option 1")

    $result2 = StringRegExp("I love rock n roll, put another dime in the juke-box baby.", "\b(the|Jazz|juke|box|n)\b",2)
    _ArrayDisplay($result2, "Return form StringRegExp() with option 2")

    $result3 = StringRegExp("I love rock n roll, put another dime in the juke-box baby.", "\b(the|Jazz|juke|box|n)\b",3)
    _ArrayDisplay($result3, "Return form StringRegExp() with option 3")

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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...