Search for last character of the same kind in a string

Discuss RoboTask here
Post Reply
pancakegh
Posts: 15
Joined: Mon Feb 16, 2015 10:21 am

Search for last character of the same kind in a string

Post by pancakegh »

Hi,

Is there a way to find the position of the last character of the same kind in a string?

for example:

I want to rename my files to "387.20.1082.jpg"
the files are all named: "nike-kaishi-grijze-lage-kinder-sneakers-24139-387.20.1082.jpg"

The text part is always different and the number of " - " symbols are always different too, depending on the names.

I know I can search for the " - " substring, but how do I find the position of the last " - " character so I can delete the piece of string up until that position? So the "387.20.1082.jpg" part remains as a result?
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Search for last character of the same kind in a string

Post by Oleg »

See below two examples

Example 1 uses Strings actions

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task177"
Hide=INTEGER|0
ID=INTEGER|-1482684932
LogOnAsUser=INTEGER|1
Name=STRING|"rename file"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""SOURNAME"" with value ""nike-kaishi-grijze-lage-kinder-sneakers-24139-387...."""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"SOURNAME"
varvalue=STRING|"nike-kaishi-grijze-lage-kinder-sneakers-24139-387.20.1082.jpg"

[Actions\Action10]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Source:"""
Params=FOLDER

[Actions\Action10\Params]
icon=STRING|"1"
msg0=STRING|"Source:"
msg1=STRING|"{SourName}"
msg3=STRING|"Result:"
msg4=STRING|"{DestName}"
msgcount=STRING|"5"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""DESTNAME"" with value ""{SourName}"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"1"
varkind=STRING|"1"
varname=STRING|"DESTNAME"
varvalue=STRING|"{SourName}"

[Actions\Action3]
ActionID=STRING|"A_STR_POS"
Enabled=INTEGER|-1
Name=STRING|"STR Pos"
Params=FOLDER

[Actions\Action3\Params]
case=STRING|"0"
from=STRING|"1"
search=STRING|"-"
source=STRING|"{DestName}"
variable=STRING|"pos"

[Actions\Action4]
ActionID=STRING|"A_LOOP_WHILE"
Enabled=INTEGER|-1
Name=STRING|"While loop"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"3"
type=STRING|"1"
value1=STRING|"{pos}"
value2=STRING|"0"

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""pos"""
Params=FOLDER

[Actions\Action5\Params]
incement=STRING|"1"
vaiable=STRING|"pos"

[Actions\Action6]
ActionID=STRING|"A_STR_EXTRACT"
Enabled=INTEGER|-1
Name=STRING|"STR Extract"
Params=FOLDER

[Actions\Action6\Params]
amount=STRING|"255"
from=STRING|"{pos}"
source=STRING|"{DestName}"
variable=STRING|"DestName"

[Actions\Action7]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|0
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action7\Params]
message=STRING|"{pos}| {DestName}"
type=STRING|"3"

[Actions\Action8]
ActionID=STRING|"A_STR_POS"
Enabled=INTEGER|-1
Name=STRING|"STR Pos"
Params=FOLDER

[Actions\Action8\Params]
case=STRING|"0"
from=STRING|"1"
search=STRING|"-"
source=STRING|"{DestName}"
variable=STRING|"pos"

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Example 2 uses regular expressions.
It is more simple but you have to be familiar with the syntax of regular expressions, of course.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task176"
Hide=INTEGER|0
ID=INTEGER|-1134236235
LogOnAsUser=INTEGER|1
Name=STRING|"rename file (regex)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""SOURNAME"" with value ""nike-kaishi-grijze-lage-kinder-sneakers-24139-387...."""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"SOURNAME"
varvalue=STRING|"nike-kaishi-grijze-lage-kinder-sneakers-24139-387.20.1082.jpg"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""DESTNAME"" with value """""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"DESTNAME"

[Actions\Action3]
ActionID=STRING|"A_REGEXP_REPLACE"
Enabled=INTEGER|-1
Name=STRING|"RegExp Replace"
Params=FOLDER

[Actions\Action3\Params]
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{sourname}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"(?U).+(\d+\.\d+\.\d+\.jpg)"
replacementcount=STRING|"0"
replacemode=STRING|"0"
repline00000000=STRING|"$1"
replinecount=STRING|"1"
singleline=STRING|"0"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"destname"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Source:"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"Source:"
msg1=STRING|"{SourName}"
msg3=STRING|"Result:"
msg4=STRING|"{DestName}"
msgcount=STRING|"5"
playsound=STRING|"0"
showmessage=STRING|"1"
Save the text of the tasks to a files and use menu Task->Import to import the task into RoboTask.
Oleg Yershov
Post Reply