Find string within another string?

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
ziltmilt
Dragon
Posts: 331
Joined: Sun Apr 29, 2007 9:28 pm
Contact:

Find string within another string?

Post by ziltmilt »

Any idea which function in Maptool can find matches for strings within another string? I saw strfind(), but it looks like it's for regular expressions. I'm looking for the equivalent to VBA's Instr() function, if it exists.

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Find string within another string?

Post by aliasmask »

strfind is the right function unless there is a certain format that string with in a string goes by that will allow something like listContains would work for. Can you give an example?

User avatar
Jagged
Great Wyrm
Posts: 1306
Joined: Mon Sep 15, 2008 9:27 am
Location: Bristol, UK

Re: Find string within another string?

Post by Jagged »

I think what you are looking for is indexOf

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Find string within another string?

Post by wolph42 »

I've created this UDF in the BoT:
Spoiler
[H: '<!-- bot_inStr -->']
[H: '<!-- 0=Text, 1=string to look for in Text -->']
[r, if(arg(1)==""):""; getFindCount(strfind(arg(0), arg(1)))]
you can load the BoT (link in sig, function call is: bot_inStr(text, lookforstring) returns true or false (1 or 0)) or make a UDF yourself and copy paste that in. As you can see its regex by the way.

ziltmilt
Dragon
Posts: 331
Joined: Sun Apr 29, 2007 9:28 pm
Contact:

Re: Find string within another string?

Post by ziltmilt »

Yep, indexOf looks exactly what I need. Thanks again!

Post Reply

Return to “Macros”