How to make "if text does not contain _ then" in Xojo?

I’m trying to make a web browser that can search with Google if the text isn’t a URL. It’s pretty simple. If the text doesn’t contain “.” (or something else) I want it to search with Google.

Here’s what I have so far:

If TextField1.text does not contain "." then

Any help with this?

If TextField1.Text.IndexOf(".") = -1 Then

1 Like

That works beautifully. Thanks!

If you do this a lot, you might want to write a string extension function:

function DoesNotContain(extends s as string, target as string) as boolean
  return s.IndexOf(target) = -1
end function

If TextField1.Text.DoesNotContain(".") then
which might be easier to read and understand.

You could even write it so it extends the textField:

function DoesNotContain(extends tf as TextField, target as string) as boolean
  return tf.text.IndexOf(target) = -1
end function

Then your code is simply:
If TextField1.DoesNotContain(".") then

1 Like