If I'm using indexOf to find the first space in the text of a token property, is it going to strip off leading spaces? It appears that it does.
It appears this trimming occurs when I access the token property. If I type in the string:
[r:indexOf(" 79 74"," ")]
I get a result of 0, but if I access the token property:
[r:indexOf(TokenProperty," ")]
and TokenProperty equals " 79 74", I get a result of two.
Am I reading this right? And can I rely on this behavior? (It would be quite convenient if I can.)
It also appears to trim off any trailing space when I access a token property, too.
Clarification on indexOf
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
Re: Clarification on indexOf
In computer science, arrays and strings start with 0. It'll return -1 if not found.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Clarification on indexOf
Yeah, I got that part. What I'm asking about is actually accessing token properties that start (or end) with a space. It appears that leading (and trailing) spaces are always trimmed off. Is that correct? I get the same indexOf for the first space for " 79 74" as I do for "79 74" - if it comes from a token property.
Re: Clarification on indexOf
I see. You are correct, there is some trimming going on that I don't think should be. But you can get the string with the spaces by using Wiki: getRawProperty().
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Clarification on indexOf
Trimming trailing spaces doesn't surprise me. Leading spaces does, a little, since they appear in the pop-up when you hover the mouse over it.
In this case, however, it's actually easier for me if it does trim leading spaces reliably. Some tokens, the properties will have leading spaces, some don't.
In this case, however, it's actually easier for me if it does trim leading spaces reliably. Some tokens, the properties will have leading spaces, some don't.
Re: Clarification on indexOf
I wouldn't rely on MT to do this since it's unusual behavior. If you want something trimmed I would use the trim function as well.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Clarification on indexOf
I'm not sure it's bad that it does this, or that it should change, since there is a way to get the raw text (as you noted). Even so, yeah, I think I'll use trim (which I had not yet discovered until now). Thank you.
Re: Clarification on indexOf
It may be convenient for you, but anything that changes data unexpectedly is a bad idea in general. It's just one of those tricks you have to know about MT.
Downloads:
- Notepad++ MapTool addon
- RPEdit details (v1.3)
- Coding Tips: Modularity and Design
- Videos: Macro Writing Tools
Re: Clarification on indexOf
I think the issue is more "unexpectedly" than "changes the data." If it's documented (and maybe it is, I didn't actually look), it's expected behavior. I really have no preference either way, personally, since there is a way to get the property text without any changes. But I'm just barely scratching the surface on what macros can do, so this may well be an important issue to some (and you'd know that better than me).
I did add in a Trim command, in case it changes in the future.
I did add in a Trim command, in case it changes in the future.