Hi,
Would like to assign the last three characters of a string variable to a new string variable. Any idea on how to do this?
Thanks!
Copy last three characters of a variable to a new variable
Moderators: Dorian (MJT support), JRL
Re: Copy last three characters of a variable to a new variable
Here is how I am currently trying to do this:
GetClipBoard>filename
Let>filenamelength={length(%filename%)}
Let>count=filenamelength-3
Let>at={Pos(" ",%filename%)}
Let>branch={copy(%filename%,count,%at%-1)}
message>branch
Branch should return the last 3 characters, but only does this if I specify manually in count.
As the code is now, I get an Unknown Identifier "COUNT" error
GetClipBoard>filename
Let>filenamelength={length(%filename%)}
Let>count=filenamelength-3
Let>at={Pos(" ",%filename%)}
Let>branch={copy(%filename%,count,%at%-1)}
message>branch
Branch should return the last 3 characters, but only does this if I specify manually in count.
As the code is now, I get an Unknown Identifier "COUNT" error
Re: Copy last three characters of a variable to a new variable
You probably have previous programming experience which will be a benefit for logic but a deficit for syntax. You need to study posted scripts and get a feel for available commands and Macro Scheduler syntax which does not allow multiple functions on the same line.
Code: Select all
GetClipBoard>filename
Length>FileName,filenamelength
Let>filenamelength={%filenamelength%-2}
Midstr>filename,filenamelength,3,branch
mdl>branch
- Marcus Tettmar
- Site Admin
- Posts: 7393
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Copy last three characters of a variable to a new variable
You've missed the % .. % around "count" as with all your other variables. That line should be:CGooley wrote: ↑Wed Jun 26, 2019 6:19 pmHere is how I am currently trying to do this:
GetClipBoard>filename
Let>filenamelength={length(%filename%)}
Let>count=filenamelength-3
Let>at={Pos(" ",%filename%)}
Let>branch={copy(%filename%,count,%at%-1)}
message>branch
Branch should return the last 3 characters, but only does this if I specify manually in count.
As the code is now, I get an Unknown Identifier "COUNT" error
Let>branch={copy(%filename%,%count%,%at%-1)}
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7393
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Copy last three characters of a variable to a new variable
CGooley's syntax is correct - it is using complex expressions. Just missed % around the count variable. But your solution works tooJRL wrote: ↑Thu Jun 27, 2019 3:21 pmYou probably have previous programming experience which will be a benefit for logic but a deficit for syntax. You need to study posted scripts and get a feel for available commands and Macro Scheduler syntax which does not allow multiple functions on the same line.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: Copy last three characters of a variable to a new variable
@CGooley,
Yeah, you could do it that way. Some people like long lines of programming to accomplish a 1 liner.
Boy! If the RegEx commission ever finds out how much I use RegEx, I am going to be in a lot of trouble!
PepsiHog
Yeah, you could do it that way. Some people like long lines of programming to accomplish a 1 liner.
Code: Select all
let>FileName=MyFilesNamelast3.txt
RegEx>.*(...)\..*,FileName,0,match,nom,1,$1,res
mdl>%res%
PepsiHog
Windows 7
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!
PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)
The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!