stringToList doesn't work with period as delimiter?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
xavram
Dragon
Posts: 891
Joined: Tue Apr 20, 2010 8:22 pm

stringToList doesn't work with period as delimiter?

Post by xavram »

Trying to break up a big blob of text by sentences but it always returns a blank for the list.

Tested it list so...

[h : theTest = "This is a test. Of the string to list. functionality"]
[h : theList = stringToList(theTest, ".")]
[r : "list = " + theList]

and what gets broadcast to the Chat window is just "list = ".

Is this a known issue? Or am I doing something really stupid here?

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

Re: stringToList doesn't work with period as delimiter?

Post by aliasmask »

I didn't know this myself, but apparently the delimiter is regex, so...

Code: Select all

[h : theTest = "This is a test. Of the string to list. functionality"]
[h : theList = stringToList(theTest, "[.]")]
[r : "list = " + theList]

LarryWoestman
Cave Troll
Posts: 28
Joined: Tue Jul 21, 2020 7:50 pm

Re: stringToList doesn't work with period as delimiter?

Post by LarryWoestman »

Another possible way to say it is that the period is a character with a special meaning when you are searching for a delimiter, so you need to tell MapTool that you just want the period and not the special meaning. "[.]" works. Another possibility is to put a "\" in front of the period, so you are using "\." as your delimiter string. However, just to confuse things, there are times when the "\" also has a special meaning. Sometimes you have to put "\\." to get the appropriate search result.

The special meaning for "." is "match one character". The special meaning for "\" is "treat the next character as just a character with no special meaning".

There is a reason why people aren't fond of regular expressions ("regex"). They are powerful but sometimes painful to get right.

paulwillis
Kobold
Posts: 1
Joined: Fri Jan 15, 2021 1:20 am

Re: stringToList doesn't work with period as delimiter?

Post by paulwillis »

The delimiter is regex.

Post Reply

Return to “MapTool”