Multi Commander > Script
MultiScript Name selection excluding file extension?
Ulfhednar:
Ahhh I hadn't got as far as thinking I could set a position qualifier on that command!
I assumed my option was either all lower or all upper when looking at the StrToUpper & StrToLower commands.
Thanks for taking the time to show me that info. ;)
Seems I can do bad things in all types of coding! :D
I will have a go at PHP/Java & see if that helps me see MS more clearly.
Ulfhednar:
It seems I can give the script a specific command for a fixed position but not one for a variable.
I have been trying to get the StrToUpper to rename multiple matches, but I couldn't get the command to work correctly with this -
--- Code: ---@var $text = "My string";
@var $pos = StrIsRegExpMatch($text, "\s[a-z]";
$text[$pos] = StrToUpper($text[$pos]);
// $text == "MY string"
--- End code ---
Should this regex work? I can't see why it chooses position 1, if the regex can be passed to it.
I've ended up looking at an array of parts - haven't cracked it yet though. ::)
Apologies in advance if I'm being a muppet! :)
Mathias (Author):
The RegEx row fails.
Try running the script in the debugger. Then you can step one line at the time
Menu> Help> Multi-Script Debugger
Also StrIsRegExpMatch return 1 the regEx and input is a match else 0.. Not the position
http://multicommander.com/docs/multiscript/functions/string#strisregexpmatch
Think you need to use StrRegExpFind if you want the position
Jungle:
Ulfhednar
1. StrIsRegExpMatch function compares string with RegEx pattern, it doesn't perform search. So it always returns 1 if success and 0 otherwise. It's a state, not position.
2. $text[$pos] = assignment modifies only one single character in the string.
So if you want to find a position of RegExp in your string, you should use StrRegExpFind function. But unfortunately it returns only position, so you [probably] can't extract matching substring.
IMHO StrRegExpFind function should be improved to return array of (pos; len) if possible.
Ulfhednar:
OK thanks guys.
Yes I can see my false expectations assumed a position value not just y/n (1/0) response. ::)
Jungle has seen my expectation/the correct idea in saying "StrRegExpFind function ...to return array of (pos; len)"
(pos; len) was the value I was wanting to pass along, but couldn't see how.
I will certainly try StrRegExpFind & see what happens.
My approach had moved to breaking the string (StrSplit) into sections using " " <space> as the delimiter (I also think a regex with \W would be more useful in some cases)
Having generated an array I just needed to figure out how to manipulate & 'reassemble' the modified string. Maybe tokenize.
I hope I am getting a better sense of things though! ;)
OT
Mathias - do you think you will have time to polish/extend the debugger functionality or is it a non-priority? I don't know how many of your users use it, even little things like having right click menu functions would be helpful to me sometimes.
Update
--- Code: ---@var $text = "My string";
@var $pos = StrRegExpFind($text, "\s[a-z]";
$text[$pos] = StrToUpper($text[$pos]);
--- End code ---
gives error
Script engine error => Failed to initialize variable "$pos" with "StrRegExpFind( $text
Script engine error => Failed to define variable - "@var $pos = StrRegExpFind( $text , "\s[a-z]""
Script engine error - Line : 1, Error : -1 => Code : "@var $pos = StrRegExpFind( $text , "\s[a-z]""
Tried different regex eg \w also fails. :-\
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version