String contains "this"

So i have my user enter s string that is stored inn string1

i want to create if statements as so

if (string1 contains “google”) then
–google search
end

So how can i detect if a string contains something? [import]uid: 59735 topic_id: 17608 reply_id: 317608[/import]

if string.find(string1,"google) ~= nil then -- google search end [import]uid: 19626 topic_id: 17608 reply_id: 67002[/import]

Missing second quote:

if string.find(string1,"google") ~= nil then -- google search end [import]uid: 95579 topic_id: 17608 reply_id: 67003[/import]

thanks, and another question. When someone enters “google this”
i want to change it to google_this or google+this

will this be possible? Change spaces to a character? Thanks [import]uid: 59735 topic_id: 17608 reply_id: 67033[/import]

havent tested this but this may work…

string.gsub(string1," ","\_") [import]uid: 69826 topic_id: 17608 reply_id: 67036[/import]

This might not be the best way, and I haven’t tested it but it ought to put an underscore between any number of words

[code]

local string1=“Google this” --the original string
local temptable={} --a temporary table to store each word

for w in string.gmatch(string1, “%w+”) do --pulls out words separated by spaces
table.insert(temptable,w)–inserts them into a table on word per row
end

local string2=temptable[1] --initialises the new string with the first word

for n=2,#temptable do
string2=string2…"_"…temptable[n] --adds all subsequent words with a dash in between
end

print(string2) – results in “google_this”

[/code] [import]uid: 95579 topic_id: 17608 reply_id: 67040[/import]

Doh! Yes, that’s done in one line what took me 14 @jammydodger!!

The full code:

string2=string.gsub(string1," ","\_") [import]uid: 95579 topic_id: 17608 reply_id: 67041[/import]

More info on string manipulation and functions here:

http://developer.anscamobile.com/content/strings-0
[import]uid: 52430 topic_id: 17608 reply_id: 67092[/import]