changing specified char in txt file

Discuss RoboTask here
tombur
Posts: 24
Joined: Mon Aug 25, 2008 11:59 pm

changing specified char in txt file

Post by tombur »

I have txt file that contains characters " ¶, ±, ¼ ". they are used in my country language. I want automatically change them to " s , a , z " Is there any way to do this. I'm trying but I have no positive results so far
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

changing specified char in txt file

Post by Oleg »

Use STR Replace action for this purpose. I've tested this, it's working.
In order to enter the special characters use Alt-<charcode> combinations.
for examle:

¶ char code is 182, use Alt-0182
¼ char code is 188, use Alt-0188
± char code is 177, use Alt-0177

press ALT and input the number on numeric keypad. Next - release ALT key.

Also you may use "Character map" system utility.
system menu Start -> All Programs -> Accessories -> System Tools -> Character map
tombur
Posts: 24
Joined: Mon Aug 25, 2008 11:59 pm

changing specified char in txt file

Post by tombur »

I've made this script and it's not working. I have problems with proper expression in the replace function;*****************************;* RoboTask Task file         ;* Do not edit in text editor!;***************************** [Root]ActionAfterRun=INTEGER|0Actions=FOLDERAutomat=INTEGER|0CatID=INTEGER|0ContinueOnError=INTEGER|0ExternalName=STRING|"Task261"Hide=INTEGER|0ID=INTEGER|946839618Name=STRING|"Search substring in text files (imported)"Priority=INTEGER|3RunOnClose=INTEGER|0RunOnStartup=INTEGER|0ToLog=INTEGER|3WriteGeneralLog=INTEGER|0[Actions]Action1=FOLDERAction2=FOLDERAction3=FOLDER[Actions\Action1]ActionID=STRING|"A_LOOP_FILE"Enabled=INTEGER|-1Name=STRING|"File Loop"Params=FOLDER[Actions\Action1\Params]createmode=STRING|"1"date1=STRING|"20080419"date2=STRING|"20080419"destvar=STRING|"C_FILE"DuringDays=STRING|"1"DuringMonths=STRING|"1"file0=STRING|"C:\test.txt"filecount=STRING|"1"OlderDays=STRING|"1"OlderMonths=STRING|"1"savesize=STRING|"0"searchkind=STRING|"0"subdirs=STRING|"1"timesize=STRING|"0"WithoutPath=STRING|"0"[Actions\Action2]ActionID=STRING|"BASIC_EVALUATE"Enabled=INTEGER|-1Name=STRING|"Evaluate"Params=FOLDER[Actions\Action2\Params]expression=STRING|"replace(""{TextFile({c_file})}""Â""'s"")"variable=STRING|"{TEXTFILE({C_FILE})}"[Actions\Action3]ActionID=STRING|"A_LOOP_END"Enabled=INTEGER|-1Name=STRING|"End Loop"
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

changing specified char in txt file

Post by Oleg »

Why do you not use "STR Replace" action? Find it in Strings group.

You have made 3 gross errors:

1. You have to use Basic script instead of Evaluate action.
Suppose your text contain a few lines:
line1
line2
line3

Your expression will be so after expanding of variables:
replace("line1
line2
line3", "Â", "s")
this is wrong

2. Variable {Textfile()} is the system variable and you can't assign anything to it
3. You wrote the exression incorrect. You must write so:
replace("{TextFile({c_file})}","Â","s")

See my example below:
;*******************************
;* RoboTask Task file         &n bsp;*
;* Do not edit in text editor! *
;*******************************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|1076699455
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task771"
Hide=INTEGER|0
ID=INTEGER|1362825492
LogOnAsUser=INTEGER|1
Name=STRING|"Search substring in text files (My Example)"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

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

[Actions\Action1]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER

[Actions\Action1\Params]
createmode=STRING|"1"
date1=STRING|"20080419"
date2=STRING|"20080419"
destvar=STRING|"C_FILE"
DuringDays=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"C:\test.txt"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"

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

[Actions\Action2\Params]
mode=STRING|"0"
replacement=STRING|"s"
source=STRING|"{TextFile({c_file})}"
substring=STRING|"Â"
variable=STRING|"MyText"

[Actions\Action3]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|-1
Name=STRING|"Create text file {C_FILE}"
Params=FOLDER

[Actions\Action3\Params]
fileexists=STRING|"0"
filname=STRING|"{C_FILE}"
line0=STRING|"{MyText}"
linecount=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

Last edited by Oleg on Fri Feb 06, 2009 12:34 pm, edited 1 time in total.
tombur
Posts: 24
Joined: Mon Aug 25, 2008 11:59 pm

changing specified char in txt file

Post by tombur »

E: 2009-02-07 12:39:10: Task can't be startedE: 2009-02-07 12:39:10: The task contains UNKNOWN steps.I do not have strings group in my robotask. or I can not find it
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

changing specified char in txt file

Post by Oleg »

What version do you use?
This is in latest version. Current version of RoboTask is 3.2.1

Also see example below:

;*******************************
;* RoboTask Task file         &n bsp;*
;* Do not edit in text editor! *
;*******************************

[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|1076699455
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task770"
Hide=INTEGER|0
ID=INTEGER|1512055805
LogOnAsUser=INTEGER|1
Name=STRING|"Search substring in text files (My Example 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

[Actions\Action1]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER

[Actions\Action1\Params]
createmode=STRING|"1"
date1=STRING|"20080419"
date2=STRING|"20080419"
destvar=STRING|"C_FILE"
DuringDays=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"C:\test.txt"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action2]
ActionID=STRING|"BASIC_SCRIPT"
Enabled=INTEGER|-1
Name=STRING|"Internal basic script"
Params=FOLDER

[Actions\Action2\Params]
line00000=STRING|"Sub Main"
line00001=STRING|"Dim s As String"
line00003=STRING|"s = RoboTaskApp.ExpandText(""{TextFile({c_file})}"")"
line00005=STRING|"'put here necessary ASCII code and symbol"
line00006=STRING|"s = Replace(s,Chr(194),""s"")"
line00008=STRING|"RoboTaskApp.SetUserVariable(""MyText"", s)"
line00010=STRING|"End Sub"
linecount=STRING|"11"
source=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_FILE_TEXTWRITE"
Enabled=INTEGER|-1
Name=STRING|"Create text file {C_FILE}"
Params=FOLDER

[Actions\Action3\Params]
fileexists=STRING|"0"
filname=STRING|"{C_FILE}"
line0=STRING|"{MyText}"
linecount=STRING|"1"

[Actions\Action4]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
tombur
Posts: 24
Joined: Mon Aug 25, 2008 11:59 pm

changing specified char in txt file

Post by tombur »

I'm using version 3.1
tombur
Posts: 24
Joined: Mon Aug 25, 2008 11:59 pm

changing specified char in txt file

Post by tombur »

I've created a txt file c:\test.txt with the content "¶"after running this;*****************************;* RoboTask Task file         ;* Do not edit in text editor!;***************************** [Root]ActionAfterRun=INTEGER|0Actions=FOLDERAutomat=INTEGER|0CatID=INTEGER|0ContinueOnError=INTEGER|0ExternalName=STRING|"Task770"Hide=INTEGER|0ID=INTEGER|1512055805Name=STRING|"convert ¶ to s"Priority=INTEGER|3RunOnClose=INTEGER|0RunOnStartup=INTEGER|0ToLog=INTEGER|3WriteGeneralLog=INTEGER|0[Actions]Action1=FOLDERAction2=FOLDERAction3=FOLDERAction4=FOLDER[Actions\Action1]ActionID=STRING|"A_LOOP_FILE"Enabled=INTEGER|-1Name=STRING|"File Loop"Params=FOLDER[Actions\Action1\Params]createmode=STRING|"1"date1=STRING|"20080419"date2=STRING|"20080419"destvar=STRING|"C_FILE"DuringDays=STRING|"1"DuringMonths=STRING|"1"file0=STRING|"C:\test.txt"filecount=STRING|"1"OlderDays=STRING|"1"OlderMonths=STRING|"1"savesize=STRING|"0"searchkind=STRING|"0"subdirs=STRING|"0"timesize=STRING|"0"WithoutPath=STRING|"0"[Actions\Action2]ActionID=STRING|"BASIC_SCRIPT"Enabled=INTEGER|-1Name=STRING|"Internal basic script"Params=FOLDER[Actions\Action2\Params]line00000=STRING|"Sub Main"line00001=STRING|"Dim s As String"line00003=STRING|"s = RoboTaskApp.ExpandText(""{TextFile({c_file})}"")"line00005=STRING|"'put here necessary ASCII code and symbol"line00006=STRING|"s = Replace(¶,Chr(182),""s"")"line00008=STRING|"RoboTaskApp.SetUserVariable(""MyText"", s)"line00010=STRING|"End Sub"linecount=STRING|"11"source=STRING|"0"[Actions\Action3]ActionID=STRING|"A_FILE_TEXTWRITE"Enabled=INTEGER|-1Name=STRING|"Create text file {C_FILE}"Params=FOLDER[Actions\Action3\Params]fileexists=STRING|"0"filname=STRING|"{C_FILE}"line0=STRING|"{MyText}"linecount=STRING|"1"[Actions\Action4]ActionID=STRING|"A_LOOP_END"Enabled=INTEGER|-1Name=STRING|"End Loop"the file is empty and it should have "s" inside
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

changing specified char in txt file

Post by Oleg »

Use this text in basic script instead of yours:

Sub Main
Dim MyString As String

MyString = RoboTaskApp.ExpandText("{TextFile({c_file})}")
MyString = Replace(MyString, Chr(182),"s")
RoboTaskApp.SetUserVariable("MyText", MyString)
End Sub

ASCII code for ¶ is 182
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

changing specified char in txt file

Post by Oleg »

Also you may download latest version and install it.
Post Reply