 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
biotech
Joined: 24 Feb 2006 Posts: 145
|
Posted: Sun Dec 09, 2007 7:17 pm Post subject: help with detecting keywords in text files |
|
|
i have to detect certain keywords in the text. so far i am doing simple thing, going through text file
in text editor coping line by line of text and comparing contents of clipboard with keywords. Some keywords
are easy to detect like "chapter" but some are harder like roman numbers I. II. III. etc with and without period after the
number, so i need some help with detecting them.
the code i am using now is:
(it is slow but gets things done over night and save me some time, if i could manage to detect those roman numbers
properly that would be great, thanks!)
| Code: |
Loop
{
clipboard=
;pick up the line of text
Send, {Home}
Send, {Shift Down}
Send, {End}
Send, {Shift Up}
Send, ^c
ClipWait, 1
;compare it woth keyword
IfInString, clipboard, %trigger%
{
Send, {Ctrl Down}
Send, {%action%} ;action is hotkey F1 or something else
Send, {Ctrl Up}
Sleep, 500
} else {
Send, {home}
Send, {down}
}
}
|
|
|
| Back to top |
|
 |
Ian
Joined: 15 Jul 2007 Posts: 1157 Location: Enterprise, Alabama
|
Posted: Sun Dec 09, 2007 8:23 pm Post subject: |
|
|
| Code: | $File = c:\whatever\whatever.txt ; replace with the path of the text file.
FileAppend, %Clipboard%, %Temp%\tempclip.txt
Loop, Parse, %$File%, `n
{
FileReadLine, Line, %$File%, A_Index
Loop, Parse, Clipboard, `n
{
FileReadLine, ClipLine, %Temp%\tempclip.txt
If (Line == ClipLine)
{
Do whatever
}
}
}
FileDelete, %Temp%\tempclip.txt
Return |
_________________ ScriptPad/~dieom/dieom/izwian2k7/Trikster/God
 |
|
| Back to top |
|
 |
biotech as guest Guest
|
Posted: Mon Dec 10, 2007 12:27 am Post subject: |
|
|
i can not use that because i have to do it inside text editor
i just need the way to detect roman numbers in line of the text. |
|
| Back to top |
|
 |
Ian
Joined: 15 Jul 2007 Posts: 1157 Location: Enterprise, Alabama
|
Posted: Mon Dec 10, 2007 3:06 am Post subject: |
|
|
Why can't you do it? I don't understand. _________________ ScriptPad/~dieom/dieom/izwian2k7/Trikster/God
 |
|
| Back to top |
|
 |
biotech as guest Guest
|
Posted: Mon Dec 10, 2007 9:23 am Post subject: |
|
|
| because i am formating text in text editor, i canot parse text file like you suggested |
|
| Back to top |
|
 |
Ian
Joined: 15 Jul 2007 Posts: 1157 Location: Enterprise, Alabama
|
Posted: Mon Dec 10, 2007 9:29 am Post subject: |
|
|
Just need to clarify one thing.
By formatting, you mean coloring/changing font right?
If so, I believe there is a way to append formatted text. _________________ ScriptPad/~dieom/dieom/izwian2k7/Trikster/God
 |
|
| Back to top |
|
 |
biotech as guest Guest
|
Posted: Mon Dec 10, 2007 9:37 am Post subject: |
|
|
| i already imported the text file in indesign so there is no parsing possible |
|
| Back to top |
|
 |
DerRaphael
Joined: 23 Nov 2007 Posts: 456 Location: Heidelberg, Germany
|
Posted: Mon Dec 10, 2007 10:05 am Post subject: |
|
|
| Code: |
text =
( Join`r`n
I. my text containing some words including some numbers such as roman
II. this is still my text
mumbo jumboII
III. Fin
sugar
IV. real fin
(c) MMVII.
salt
)
re := "S)((M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3}))?\.)"
loop, Parse, text, `n, `r
{
Position := RegExMatch(A_LoopField, re)
if !(Position)
MsgBox % A_LoopField "`r`nLine " A_Index ": has no Roman number"
else
MsgBox % A_LoopField "`r`nLine " A_Index ":" Position
}
|
The RegEx matches any found roman number and the msgbox returns its position
This expression has been found here
greets
DerRaphael
edit to check if a roman number is in the text, all you have to do is check if Position is different to 0. in such a case an occurence was found. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|