AutoHotkey Community

It is currently May 26th, 2012, 10:19 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Ignor a minus sign?
PostPosted: October 25th, 2009, 12:46 am 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
This is probably very simple to fix.

I have text in a file like this

[color=darkred] 002=SMALL CAPPUCCINO -1.50
002=


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 25th, 2009, 1:30 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Well you're trying to obtain information more by the pattern of the characters than the characters themselves, sounds like a job for regular expressions:

Code:
loop
{
  FileRead, currslip, c:\Uniwell\currslip.txt
  FileAppend
    , % RegExReplace(currslip,".*SUBTOTAL.*?(\d+\.\d+).*","$1")
    , c:\Uniwell\input.txt
  Sleep, 100
  Filedelete c:\Uniwell\currslip.txt
}
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 25th, 2009, 2:33 am 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Just got it like this....

Code:
If (instr(currslip,"- ")) AND (instr(currslip,"C a r d"))

{
  needle := "SUBTOTAL"
  halfslip := SubStr(currslip, InStr(currslip, needle) + StrLen(needle))
  refund := SubStr(halfslip, 1, InStr(halfslip, "`n") - 1 )
  stringReplace, amount, refund, `-, ,

  StringSplit, T, L14, %A_Space%
  output = 2=20`n1=%T1%`n3=%amount%`n99=0
  FileAppend, % output, c:\Uniwell\input.txt
  Sleep, 100
  Filedelete c:\Uniwell\currslip.txt
}

}
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 25th, 2009, 10:47 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
some examples
Example=1
Code:
setworkingdir, %a_scriptdir%
transform,S,chr,32   ;SPACE

F1=%A_scriptdir%\input12.txt
F2=%A_scriptdir%\output12.txt
;filedelete,%F1%

;------- for test --------------
AA=
(
002= SMALL CAPPUCCINO -1.50`r
002= SUBTOTAL   -1054.35   `r
002= C a r d - 4 . 3 5`r
002= CHRIS`r
)

ifnotexist,%F1%
  fileappend,%AA%,%F1%
ifexist,%F2%
  filedelete,%F2%
;-----------------------------------

FileRead, FileContent, %F1%
Loop, Parse, FileContent, `n, `
  {
  LR=%A_Loopfield%
  if A_LoopField contains SUBTOTAL
     stringreplace,LR,LR,-,%S%,all
  if A_LoopField contains C a r d
     stringreplace,LR,LR,-,%S%,all
  fileappend,%LR%,%F2%
  }
run,%F2%
return


Example=2 ABS removes minus sign
Code:
setworkingdir, %a_scriptdir%
transform,S,chr,32   ;SPACE
SetFormat, float, 0.2
F1=%A_scriptdir%\input12.txt

;------- for test --------------
AA=
(
002= SMALL CAPPUCCINO -1.50`r
002= SUBTOTAL   -1054.35   `r
002= C a r d - 4 . 3 5`r
002= CHRIS`r
)

ifnotexist,%F1%
  fileappend,%AA%,%F1%

SEARCHFOR=SUBTOTAL
   Loop,Read,%F1%
      {
      if A_LoopReadLine contains %SEARCHFOR%
         {
         Loop, Parse,A_LoopReadLine ,%S%,`
             {
             C=%A_LoopField%
             if (A_LoopField="")
                continue
             A=%C%
             }
          B:=(ABS(A))
          msgbox,%B%
         }
      }
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 25th, 2009, 3:49 pm 
Offline

Joined: September 1st, 2008, 2:50 am
Posts: 56
Code:
  stringReplace, amount, refund, `-, ,

Works well.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: AndyJenk, Bing [Bot], JSLover, Leef_me, patgenn123, rbrtryn, XstatyK and 71 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group