Page 1 of 1
Text extraction
Posted: Sat Apr 15, 2006 8:42 am
by Tacpdav
Can anyone shed a little light on a simple way to extract specific text from a file?
When this text file is created on my PC I want to extract the phone number.
At this point I am able to do it by finding and eliminating the fields that remain constant: [SMS-IN], ModemName=COM2, Sender=, Data=* and Binary=0. The problem is that the data field can vary significantly so my idea will not function in a live environment.
[SMS-IN]
ModemName=COM2:
Sender=+15551234567
Data=test
Binary=0
Any help would be greatly appreciated.
Text extraction
Posted: Sat Apr 15, 2006 10:17 am
by Oleg
Try the example below. This task extracts the phone number from string "Sender=Any_phone_number". Also, you can put this line into any position in your text.
;**********************
;* RoboTask Task file *
;* Do not edit! *
;**********************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1614811947
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task404"
Hide=INTEGER|0
ID=INTEGER|280873439
Name=STRING|"Extract phone number from text"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""PHONE_NUMBER"" with value """""
Params=FOLDER
[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"PHONE_NUMBER"
[Actions\Action2]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER
[Actions\Action2\Params]
destvar=STRING|"C_LINE"
line0=STRING|"[SMS-IN]"
line1=STRING|"ModemName=COM2:"
line2=STRING|"Data=test"
line3=STRING|"Binary=0"
line4=STRING|"Sender=+15551234567"
linecount=STRING|"6"
sourcetext=STRING|"1"
[Actions\Action3]
ActionID=STRING|"A_VARIABLES_DELIMITED"
Enabled=INTEGER|-1
Name=STRING|"Delimited Variable"
Params=FOLDER
[Actions\Action3\Params]
colon=STRING|"0"
comma=STRING|"0"
other=STRING|"1"
otherchar=STRING|"="
quote=STRING|"0"
semocolon=STRING|"0"
space=STRING|"0"
spaceasone=STRING|"0"
string=STRING|"{c_line}"
tab=STRING|"0"
variable=STRING|"c_line"
[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action4\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"0"
value1=STRING|"{c_line(0)}"
value2=STRING|"sender"
[Actions\Action5]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""PHONE_NUMBER"" with value ""{c_line(1)}"""
Params=FOLDER
[Actions\Action5\Params]
expand=STRING|"1"
varname=STRING|"PHONE_NUMBER"
varvalue=STRING|"{c_line(1)}"
[Actions\Action6]
ActionID=STRING|"A_LOOP_BREAK"
Enabled=INTEGER|-1
Name=STRING|"Break"
[Actions\Action7]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action8]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action9]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Phone number is: {phone_number}"""
Params=FOLDER
[Actions\Action9\Params]
icon=STRING|"1"
msg0=STRING|"Phone number is: {phone_number}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
Text extraction
Posted: Sat Apr 15, 2006 12:25 pm
by Tacpdav
Oleg,
Very impressive! It works flawlessly and saved me so much time.
Are there any reference materials that you recommend that would help me to become as skilled with this software as you are?
Many Thanks!
Text extraction
Posted: Sat Apr 15, 2006 1:33 pm
by Tacpdav
Oleg,
The current task includes “+1”. My messaging program interprets the “+” sign as “!” . This does not prevent the message from sending, but the recipient can not reply. I tried a few times to modify your code to exclude the “+”, but I have not been successful. Could you point out the area to be modified to make this change?
Text extraction
Posted: Mon Apr 17, 2006 3:26 am
by Oleg
Usually phone number contain 10 symbols (city code and phone number).
You can cut last 10 symbols from {PHONE_NUMBER} variable.
Insert Evaluate action (from BASIC plugin) before Break with expression
Right("{PHONE_NUMBER}",10)