SUNiNET - Your Eggdrop & TCL resources site
[ Home Eggdrop TCL Links About ]

Guide to TCL scripting for Eggdrop 1.6

[ Previous ] [ Index ] [ Next ]

9.4 Matchting strings against each other

At some points you might want to know if a certain piece of text is in a string. You can find out if it is or is not with the string match command.
The syntax of a string match command is string match <pattern> <string>.

The <pattern> is what you want to look for in the string.
Besides normal characters you can also put an asterix (*) or question mark in the pattern.
An asterix means that anything is matched and a question mark only one character.
For example if you have "*foo*" as <pattern> string match would find a match if it finds "foo" anywhere in the string, so if it was looking for "*foo*" in "test foobar" it would give a match. If you were to use "?foo*" it would find a match only if the string has the characters "foo" on the second through fourth place regardless of any suffixes, so if it was looking for "?foo*" in "test foobar" it would not match but "*foobar" would match.

The <string> is the string in which string match will look for the <pattern>.
This can be anything from a variable string to a command that outputs a string.

The string match outputs a 1 if it finds a match and 0 if it doesn't.

[ Previous ] [ Index ] [ Next ]

Design & Graphics by Shawn Borton
Copyright © 2000-2005 Marijn van Zon