Find in string

BlitzMax Forums/BlitzMax Programming/Find in string

Zenn Lee(Posted 2007) [#1]
Is there a function that will look through a string and if it contains another string it will return true. For example, lets say you had a string

Global Str$ = "My name is Bob."

and you want to know if it contains the string "Bob". How would you do that.

Thanks


JoshK(Posted 2007) [#2]
Instr$()


Zenn Lee(Posted 2007) [#3]
Wow, that's it? Great, I forgot about that function, thanks.


jsp(Posted 2007) [#4]
Str.Contains( "Bob" )

Contains Returns true if a string contains subString


Zenn Lee(Posted 2007) [#5]
Oh, I think that looks more like it. Thanks jsp.


Zenn Lee(Posted 2007) [#6]
But it can't find the function Contains().


jsp(Posted 2007) [#7]
Global Str$ = "My name is Bob."
Print Str.Contains( "Bob" )
Print Str.Contains( "BMAX" )

run it to see the result

EDIT: And it is a Method not a Function


Zenn Lee(Posted 2007) [#8]
OOP, errr.

Thanks though.


Perturbatio(Posted 2007) [#9]
Take a look in the help at Language->Strings this lists all the methods available for strings.


altitudems(Posted 2007) [#10]
Dont forget the find method if you want to know where the sub string is:

Local str:String = "My Name is Bob"
Local pos:Int = str.Find("Name")


DirtBikeDude(Posted 2007) [#11]
How could I the Character at a Position of a String?


tonyg(Posted 2007) [#12]
How could I <????> the Character at a Position of a String?



One vital word missing from your question. Anyway, look for right$, left$, mid$ if the missing word is 'find'.


DirtBikeDude(Posted 2007) [#13]
Sorry, yes I meant find. What is the syntax of those commands?
I need to return a single character.


Yan(Posted 2007) [#14]
Local str$ = "hello"

Print Chr$(str$[4])
'..or..
Print str$[4..5]



tonyg(Posted 2007) [#15]
What is the syntax of those commands?

Type, for example, 'right$' in the IDE and press F1 for syntax. Press F1 again for the command reference.