AutoHotkey Community

It is currently May 27th, 2012, 1:03 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 194 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8, 9, 10 ... 13  Next
Author Message
 Post subject:
PostPosted: January 3rd, 2010, 10:11 pm 
Offline

Joined: December 20th, 2009, 10:58 am
Posts: 15
Thanks
Not to sure I understand the first part ?
Would that just match on b ??

As for the second part it 'should' always be at the end in the same position.. But it will always be a single character at the right most position.

Is it possible to read the line right > left and capture the first character ?

Thanks for your advice :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2010, 12:51 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
1) The "b" was only an example of how to use XTF_Find.

2) You can use TF_Readlines to read the first line and use StrLen to determine the length of the lines and use that value for TF_ColGet and a simple StringReplace to remove the `n as I explained earlier.
Code:
Text=
(
aMode,,0000003e,4
aMode,,0000003e,A
aMode,,0000003e,C
aMode,,0000003e,3
)

LastCol:=StrLen(TF_ReadLines(Text, 1, 1, 1))
LastChars:=TF_ColGet(Text, 1, 0, LastCol, LastCol)
StringReplace, LastChars, LastChars, `n,,All
MsgBox % LastChars
and no I'm not going to strip these functions for you.

As an alternative to 2) you probably could use a regexmatch/replace to do the same

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2010, 10:27 pm 
Offline

Joined: December 20th, 2009, 10:58 am
Posts: 15
Thanks Hugov

Unfortunately that didn't work.. :(
Code:
GetLine:=TF_Find(ReceivedData,"","","disengage",1,1)

In this ReceivedData is a constantly streaming / changing variable.

I suppose what I need it to do is capture each entry that has aMode, grab the last digit and repeat doing this until a new command presents.

eg:
aMode,,0000003e,4
aMode,,0000003e,A
aMode,,0000003e,C
aMode,,0000003e,3
upDating,8765,Server

I should then have the full string of aMode characters in a var to use.
But how the heck do I do that !!

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2010, 11:01 pm 
Offline

Joined: December 20th, 2009, 10:58 am
Posts: 15
Manage to get this far:

Code:
if ReceivedData contains aMode
GetLine:=TF_Find(ReceivedData,"","","aMode",0,1)
StringSplit, amode, GetLine, `,,
if amode4 is number
MsgBox % amode4

This returns each entry.. How do I join them ? amode4 + amode4 etc ..

I'm wondering if this would work ??
Code:
if ReceivedData contains aMode
{
GetLine:=TF_Find(ReceivedData,"","","aMode",0,1)
StringSplit, amode, GetLine, `,,
var:=amode4 + amode4 etc..  HELP On this
if receivedData not contains aMode
MsgBox % var
}


Would that work ?? Or something similar ?

Many Thanks :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2010, 9:04 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Because aMode lines can be different length and can have a varying number of commas stringsplit might not be best, a simple parsing loop might do the trick. Pretty basic stuff really, why don't you want to learn the basics of AHK it is all very well documented
Code:
test=
(join`n
aMode,,A0000003e,4
aMode,,,,,,0000003e,A
aMode,0000003e,C
aMode,,0000003e,3
aMode,,00xx,Z
)
var=
Loop, Parse, test, `n, `r
    var .= SubStr(A_LoopField, InStr(A_LoopField, ",", false , 0) + 1, 1)
MsgBox % var
Sorry, but this is the last I'll do for your script.

Edit: it is nice idea to introduce a get column X from the right regardless of the length of the lines, I'll put it on my to TODO list... :wink:

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2010, 1:13 am 
Hi folks!

Why isn't it possible to use a variable for "Text" in "TF_Replace"? Somehow I can't use relative paths. Any suggestions?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 17th, 2010, 1:20 am 
badcoder wrote:
Why isn't it possible to use a variable for "Text" in "TF_Replace"? Somehow I can't use relative paths. Any suggestions?


Ah... I've forgot to remove the " marks.


Report this post
Top
  
Reply with quote  
 Post subject: Our "low-key" dialogue
PostPosted: January 26th, 2010, 6:11 pm 
Offline

Joined: January 24th, 2009, 3:22 pm
Posts: 13
Location: Aldersbach, Germany
Hallo!
I have completed my first piece of documentation and would like to share it with you before any of the material is seen by other forum members.
I have taken much longer than I had intended but, I have been productive.
The results are interesting:
I propose the following.
If you send me a private email adress, I will send you the introduction.
Depending on your level of interest, then I can send you the rest of the material.
The introduction will have references to the remainder of the material.
I hope to hear from you and I do apologise for the inordinate delay.
I hope that you enjoyed your Christmas and the New Year celebrations.
Regards, forkinpm.

_________________
I am building my platform based on a set of steps to take my English texts through segmenting into phrases, resequencing segments based on German rules, adding head-words and then translating with my dictionary.
Regards, forkinpm.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2010, 3:52 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
can someone explain what is wrong with this code? i'm trying to remove all lines that ends with a "\" but somehow it doesn't work..

Code:
#Include %A_ScriptDir%\tf.ahk

F=!C:\Temp\Startup_log.ini
TF_RegExReplace(F, ".*\\\s*$", "")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2010, 7:42 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
badmojo wrote:
can someone explain what is wrong with this code? i'm trying to remove all lines that ends with a "" but somehow it doesn't work

Code:
F=
(join`r`n
hello this
is a Text  \
to see how it
works \
bye bye
)
MsgBox % TF_RegExReplace(F, "im)(.*)\\\s*$", "$1")
you have to remember the parts before the \ and put it back via $1

Edit: oops I read the question incorrectly, this should do the trick
Code:
F=
(join`r`n
hello this
is a Text  \
to see how it
works \
bye bye
)
MsgBox % TF_RegExReplace(F, "m).*\\\s*", "")
The secret is in the m) see the regex docs

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2010, 7:56 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
ah, i see.. the 'm' stands for multiple lines, i guess.. thanks.

the help files mentions (?im) as the method to switch options, why in TF, the opening bracket is dropped? just curious..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2010, 8:03 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
badmojo wrote:
the help files mentions (?im) as the method to switch options, why in TF, the opening bracket is dropped? just curious..


The doc says http://www.autohotkey.com/docs/commands/RegExMatch.htm
Quote:
Options (case sensitive)
At the very beginning of a regular expression, specify zero or more of the following options followed by a close-parenthesis. For example, the pattern "im)abc" would search for abc ...
so the options don't start with a ( but do end with a )

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 9:48 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Update v3.2:

- Fixed: TF_AlignRight, due to a bug it didn't work as it should have, it prepended the number of spaces rather than aligning the text at the specified width

- Changed: TF_SplitFileByLines: New options for SplitAt, now three methods available, see notes at function description (split at specific lines or alternating lines)

- Changed: TF_RemoveLines: New option for StartLine, if negative value is used it will remove the last X lines from file, see notes at function description

- Changed: TF_GetData (helper function) should now avoid unnecessary IfNotExist for files, for scripts with many loops in combination with variables it should improve the speed slightly

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Last edited by SoLong&Thx4AllTheFish on February 20th, 2010, 2:58 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 9:57 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Experimental function: SwapLines

This function will allow you to swap lines in a variable or text file, valid options:

1,5 -> Swap lines 1 and 5
1-5,13-27 -> swap lines 1 to 5 with lines 13-27

To test this function you do need TF.ahk, see first post, as it depends on some helper functions.

Not sure if it should be added to TF, so give it a spin and let me know if you have any suggestions or find errors

Code:
;#include tf.ahk ; remove comment if you don't include TF in your library
test=
(
1-this is line 1
2-this is line 2
3-this is line 3
4-this is line 4
5-this is line 5
6-this is line 6
7-this is line 7
8-this is line 8
9-this is line 9
10-this is line 10
)

MsgBox % TF_SwapLines(test, "2,4")
;MsgBox % TF_SwapLines(test, "1-5,6-12") ; Note 12 > end of file, should work correctly
;MsgBox % TF_SwapLines(test, "2-4,8-10")
;MsgBox % TF_SwapLines(test, "1-2,5-10")
;MsgBox % TF_SwapLines(test, "1,5-10")
;MsgBox % TF_SwapLines(test, "2-4,8")
;MsgBox % TF_SwapLines(test, "1,10")

; swap 2 lines or two sections of lines in a text file, HugoV
TF_SwapLines(Text, SwapLines)
   {
    IfInString, SwapLines, + ; check if "incremental" values where used if so Return
      Return
    StringReplace, SwapLines, SwapLines, `,,`,, UseErrorLevel
    If (ErrorLevel > 1) ; too many parameters
      Return
    TF_GetData(OW, Text, FileName)   
    StringSplit, Line, Text, `n, `r
    Text=
    Loop % Line0
      Order .= A_Index ","
    Order:= "," . Order
    IfInString, SwapLines, - ; check if it is a section of lines if so make use of MakeMatchList
      {
       StringSplit, Swap, SwapLines, `,
       Loop % Swap0
          If (InStr(Swap%A_Index%,"-") > 0)
             {
             StringSplit, SectionsCheck, Swap%A_Index%, - ; built in check to see if last line of swap section isn't beyond end of file to prevent inserting empty lines
             If (SectionsCheck2 > Line0)
               Swap%A_Index% := SectionsCheck1 "-" Line0
             Swap%A_Index% := _MakeMatchList(TextFile, Swap%A_Index%)
            }
      }
    Else ; just swap two lines
      {
          StringSplit, Swap, SwapLines, `,
       }
    StringReplace, Order, Order, `,%Swap2%`,, `,%Swap1%`,
    StringReplace, Order, Order, `,%Swap1%`,, `,%Swap2%`,
    StringTrimRight, Order, Order, 1 ; remove trailing ,             
    StringTrimLeft, Order, Order, 1 ; remove leading ,             
    Loop, Parse, Order, `, ; create output with lines in the new order (the swapped lines)
      ; Text .= Line%A_Index% "|" Line%A_LoopField% "`n" ; test line remove comment and comment line below to show test results side by side
      Text .= Line%A_LoopField% "`n"
     Return TF_ReturnOutPut(OW, Text, FileName, 0)
    }

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2010, 12:20 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I have looked in but dont know how it works. Here is mine version of basic swapping two lines only. It determines and preserves correct new line of file or source string. Developed it in some hours. So it may contain some stupid bugs. May be it have some lines which gives you any idea for your own function.

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

test=
(
1-this is line 1
2-this is line 2
3-this is line 3
4-this is line 4
5-this is line 5
6-this is line 6
7-this is line 7
8-this is line 8
9-this is line 9
10-this is line 10
)

; just swap line 3 with 4.
swapped1 := swaplines(test, 3, 4)
msgbox %swapped1%

; puts 6 at position after 10. because there is no more then 10 lines.
swapped2 := swaplines(test, 6, 12)
msgbox %swapped2%

swaplines(ByRef _source, _start, _end)
{
    If (r := InStr(_source, "`r") ? "`r" : "")
    {
        nchar := "`r`n"
        nlen := 2
    }
    Else
    {
        nchar := "`n"
        nlen := 1
    }
    Loop, Parse, _source, `n, %r%
    {
        If (A_Index < _start)
        {
            beginLines .= A_LoopField . nchar
        }
        Else If (A_Index > _end)
        {
            endLines .= A_LoopField . nchar
        }
        Else If (A_Index = _start)
        {
            swapLine1 := A_LoopField . nchar
        }
        Else If (A_Index = _end)
        {
            swapLine2 := A_LoopField . nchar
        }
        Else
        {
            swapLinesBetween .= A_LoopField . nchar
        }
    }
    new := beginLines . swapLine2 . swapLinesBetween . swapLine1 . endLines
    StringTrimRight, new, new, %nlen%
    Return new
}


edit: removed an unnecessary line.

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Last edited by Tuncay on February 20th, 2010, 3:20 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 194 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8, 9, 10 ... 13  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 8 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