I am trying to make sense of the strfind function but am not having much success. What I am trying to accomplish is I have a string "[name] (Major)" and I want to save a new string with just "[name]", essentially, stripping off the " (Major)" from the end. [name] is a string consisting of letters and some of them have a special character like an ' or ! and it can be any length.
Maybe strfind is not the best way to do it and there is an easier way. Any ideas or suggestions?
Trying to extract the beginning of a string
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: Trying to extract the beginning of a string
Is name in []'s? Is Major in ()'s?
So, if name is any character, except ()'s, then you can just use ( as the list breaking point.
So, if name is any character, except ()'s, then you can just use ( as the list breaking point.
Code: Select all
[H: name = listget(myString,0,"(")]
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Trying to extract the beginning of a string
this is a lot easier if you give some examples
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
Re: Trying to extract the beginning of a string
No, [Name] is not actually in [], but (Major) is in (). An example would be "Bad Eyes (Major)" and I want to remove "(Major)" so I wind up with just the string "Bad Eyes" or "Bad Eyes " is fine also if leaving the blank space would be easier. I am writing a macro to downgrade a major hindrance in SWADE to the minor version, or remove the hindrance if it is a minor already or has no minor/major versions. I have everything else working as far as I can tell except for this swapping part. The player selects the hindrance from a dropdown list which is populated from their current hindrances. The one they select is removed. Then I check to see if they have selected one with (Major) at the end. If they have, it should strip off the (Major), add (Minor), and use that to look to see if the minor version exists in the library token. If it does, it adds the minor one to the character.
Re: Trying to extract the beginning of a string
Ohhh, I get it and that is creative. I didn't think listGet was what I needed as this wasn't a string list but I see you are designating the ( as the delimiter and treating it like a string list. If I set the delimiter as " (" instead, would that get rid of the blank space between "Name" and "(Major)"?aliasmask wrote: ↑Sat Sep 26, 2020 2:23 amIs name in []'s? Is Major in ()'s?
So, if name is any character, except ()'s, then you can just use ( as the list breaking point.
Code: Select all
[H: name = listget(myString,0,"(")]
- Full Bleed
- Demigod
- Posts: 4736
- Joined: Sun Feb 25, 2007 11:53 am
- Location: FL
Re: Trying to extract the beginning of a string
Looks like you can do this to do that:
Code: Select all
[h: name = "Tom (Major)"]
[r: newName = replace(name, "(Major)", "Minor")]
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."
Re: Trying to extract the beginning of a string
That is an elegant solution too and combines both steps together, thanks!