Example of using the Method 'Contains'

Monkey Forums/Monkey Beginners/Example of using the Method 'Contains'

MonkeyPlotter(Posted 2015) [#1]
Have been trying to use the Method 'Contains' to establish if a certain line read from a text file starts with "<distancemetres>", however I am struggling to write syntax which will compile.

Once I can establish if a certain readline contains "<distancemetres>" then I intend to do some string operations on it - however the first step is eluding me.

Can anyone please show me an example of using the method 'Contains' ? Thanks.


Pharmhaus(Posted 2015) [#2]
Local str:String = "Hello World!"

If str[0 .. 5] = "Hello" Then
	Print "Using Slices from 0 (including) to 5 (excluding)"
EndIf

If str.StartsWith("Hello") Then
	Print "Using starts with"
EndIf

If str.Contains("Hello") Then
	Print "Nice to see you"
EndIf

If "Hello World!".Contains("World") Then
	Print "No variable"
EndIf

Local dim:String = "<1000> fdkhgklfdgkfdhkghdf"
Local dimInt:int = int(dim[dim.Find("<") + 1 .. dim.FindLast(">")])
Print dimInt



Pharmhaus(Posted 2015) [#3]
I just rememberd that both degac and ImmutableOctet offer functions similiar to the classic Bmax/B3d commands.
Just in case you would prefer that for converting existing code:
*Click*
*Click*


rIKmAN(Posted 2015) [#4]
I didn't know about that last one, handy!

Thanks Pharmhaus.


MonkeyPlotter(Posted 2015) [#5]
OMG, been meaning to get back and try Pharmhaus's initial suggestion for about 7 hours but other commitments stopped me, and when I come to try it out there is numerous ways to skin the proverbial cat.

@Pharmhaus, that worked a treat, thankyou ;)

Also, there some more string manipulation examples in this thread:

http://www.monkey-x.com/Community/posts.php?topic=7619