Remove everything in string past "-"

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

Remove everything in string past "-"

Post by pancakegh »

Hi,

Is there a way to remove an amount of characters at the end of the string to the beginning?

say I have the variable {PROJECT} wich contains 12345-123.12.123
I only want to delete the 123.12.123 part of the string wich would be 10 characters from the back of the string.

Why delete a piece of string from the back? Because there are also files named 1234-123.12.123 so I can't go and delete from a specific point like 6 characters from the beginning.

Anyone know of a solution to delete everything past the "-" symbol?
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Remove everything in string past "-"

Post by Oleg »

Look at my example below.
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.

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|"Task43"
Hide=INTEGER|0
ID=INTEGER|1467404855
LogOnAsUser=INTEGER|1
Name=STRING|"delete a part of string"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

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

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""PROJECT"" with value ""12345-123.12.123"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"PROJECT"
varvalue=STRING|"12345-123.12.123"

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

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

[Actions\Action3]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action3\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"1"
value1=STRING|"{pos}"
value2=STRING|"0"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Symbol ""-"" is not found"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"3"
msg0=STRING|"Symbol ""-"" is not found"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_FLOW_EXIT"
Enabled=INTEGER|-1
Name=STRING|"Exit"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action7]
ActionID=STRING|"A_STR_DELETE"
Enabled=INTEGER|-1
Name=STRING|"STR Delete"
Params=FOLDER

[Actions\Action7\Params]
amount=STRING|"999"
from=STRING|"{pos}"
source=STRING|"{project}"
variable=STRING|"project1"

[Actions\Action8]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""old string: {project}"""
Params=FOLDER

[Actions\Action8\Params]
icon=STRING|"1"
msg0=STRING|"old string: {project}"
msg1=STRING|"new string: {project1}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"
Oleg Yershov
pancakegh
Posts: 15
Joined: Mon Feb 16, 2015 10:21 am

Re: Remove everything in string past "-"

Post by pancakegh »

Thanks Oleg!

It works well.

Another question: Is there a way I can delete everything before {pos}?

I want to extract everything behind " - " e.g: 123.12.123 as result
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Remove everything in string past "-"

Post by Oleg »

Yes, of course
See the example below

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|"Task46"
Hide=INTEGER|0
ID=INTEGER|4223397
LogOnAsUser=INTEGER|1
Name=STRING|"delete a part of string #2 (before POS)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

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

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""PROJECT"" with value ""12345-123.12.123"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"PROJECT"
varvalue=STRING|"12345-123.12.123"

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

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

[Actions\Action3]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action3\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"1"
value1=STRING|"{pos}"
value2=STRING|"0"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Symbol ""-"" is not found"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"3"
msg0=STRING|"Symbol ""-"" is not found"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_FLOW_EXIT"
Enabled=INTEGER|-1
Name=STRING|"Exit"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action7]
ActionID=STRING|"A_STR_DELETE"
Enabled=INTEGER|-1
Name=STRING|"STR Delete"
Params=FOLDER

[Actions\Action7\Params]
amount=STRING|"{pos}"
from=STRING|"1"
source=STRING|"{project}"
variable=STRING|"project1"

[Actions\Action8]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show both strings"
Params=FOLDER

[Actions\Action8\Params]
icon=STRING|"1"
msg0=STRING|"old string: {project}"
msg1=STRING|"new string: {project1}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"
Oleg Yershov
Post Reply