AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 194 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12, 13  Next
Author Message
 Post subject:
PostPosted: March 6th, 2010, 8:24 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
There are various methods to go about it, one would be to use TF_Find to find the lines and pass these on to TF_RemoveLines like so:
Code:
text=
(join`r`n
this is test
with a number of lines
to show how you
can delete "names" from a
file or variable
)

MsgBox % TF_RemoveLines(Text, TF_Find(text, "", "", "with a number of lines|file or variable", 0))
Note TF_Find uses RegEx so the | means search sentence a OR sentence b

Another method would be to use TF_Replace but you would be left with empty lines unless you use `r`nto show how you`r`n but these fail with the first and lastlines because they don't start or end with `r`n. You could use TF_ReplaceInLines but you are left with empty lines as well OR you could have a look at TF_Substract where lines in list1 are removed in list2.

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 8:55 pm 
so if i had a variable like this :
LinesToDel = line2|another line|random

TF_RemoveLines("!Text.txt", TF_Find("!Text.txt", "", "", LinesToDel, 0))

this would work? i tried it and it removed everything from the text file

then i tried this :

TF_Substract(LinesToDel, "!Text.txt", "0")

and it didnt remove anything


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 9:22 pm 
ok never mind
i got it to work with TF_Substract

i was just doing it completely wrong


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2010, 2:02 pm 
Offline

Joined: March 24th, 2010, 1:58 pm
Posts: 6
Location: Krailling, Germany
This is great work. A deep thank-you to hugov! :D

Greetz, sunfire


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 24th, 2010, 2:15 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
@sunfire: thats nice to hear. I'm always curious what functions people use and if they have any suggestions ...

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2010, 4:48 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Update v3.3, 16 April 2010

* Fixed: If you used variables with any of the replacement functions or tried to remove empty lines from a VARIABLE in the following format: variable:=TF_..(variable,"search","replace") and the searchtext was NOT present in the variable it returned an empty variable (e.g. deleted the contents of "variable")
It affected TF_ReplaceInLines, TF_Replace, TF_RegExReplaceInLines, TF_RegExReplace, TF_RemoveBlankLines, TF_RangeReplace
The built-in check only worked correctly for FILES and with the introduction of variables in TF 3 this didn't surface during the test :-(

* Fixed: documentation error for TF_Merge (seperator and filename where swapped) and added examples on how to use TF_Merge in a Loop and with FileSelectFile

Bug reports welcome as I just found the bug and fixed it... :oops:

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2010, 7:45 pm 
Offline

Joined: May 15th, 2009, 2:40 am
Posts: 15
Hi I am trying to search a file for certain text and have it tell me the line. Then I store that line number in a variable and have the TF_RemoveLines function remove the line number present in the variable...

Here is what I have.


Code:
settingspingline1:=TF_Find("!settings.ini", "", "", "SettingsManager.floatSet", 1, 0)

If settingspingline1 != 0
{
TF_RemoveLines("!settings.ini", "%settingspingline1%,%settingspingline1%")
MsgBox, Values removed!
}


What the script is doing is deleting all the contents of the settings.ini file instead of just the line I stated in the function.


I hope someone can help...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2010, 7:56 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Your code highlighting the errors:

Code:
settingspingline1:=TF_Find("!settings.ini", "", "", "SettingsManager.floatSet", 1, 0) ; no need for the ! with TF_Find as it doesn't change the file it always returns a variable

If settingspingline1 != 0
{
TF_RemoveLines("!settings.ini", "%settingspingline1%,%settingspingline1%")
MsgBox, Values removed!
}


correct:

Code:
settingspingline1:=TF_Find("settings.ini", "", "", "SettingsManager.floatSet", 1, 0) ; ! removed

If settingspingline1 != 0
{
TF_RemoveLines("!settings.ini", settingspingline1,settingspingline1) ; removed " and % just pass on the variable settingspingline1
MsgBox, Values removed!
}


This should work.

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2010, 8:06 pm 
Offline

Joined: May 15th, 2009, 2:40 am
Posts: 15
hugov


Thank you for a very quick and detailed response. This has remedied my problem and now I may continue to program!


Again I appreciate your assistance. :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2010, 3:59 pm 
Offline

Joined: May 15th, 2009, 2:40 am
Posts: 15
Sorry to bother you again Hugo but I have run into another issue...


I am trying to write text to a line in a file...and it writes fine and to the proper place...but it is not writing the value of a variable...


Here is my code...

Code:
TF_InsertLine("!settings.ini","31",31,"SettingsManager.floatSet GSDefaultLatencyCompensation 0.0%ping%0000")
TF_InsertLine("!settings.ini","32",32,"SettingsManager.U32Set GSInterpolationTime %ping%")


and in the file it gives me

SettingsManager.floatSet GSDefaultLatencyCompensation 0.0%ping%0000
SettingsManager.U32Set GSInterpolationTime %ping%



I have also tried ping without the percent signs. Is there any way I can get this to work?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2010, 9:28 pm 
Offline

Joined: May 15th, 2009, 2:40 am
Posts: 15
Never mind...I discovered a solution myself. If there is anyone here with a similar dilemma here is the solution.

You have to insert the line with the variable you want in the text. NO percent marks here.

Code:
TF_InsertLine("!settings.ini","31",31,"SettingsManager.floatSet GSDefaultLatencyCompensation 0.ping0000")


Then replace the text of the variable with the actual value of the variable

Code:
TF_ReplaceInLines("!settings.ini","31",31,"ping",ping)



And then you can write any variable in your script into a file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2010, 7:41 am 
You also can do it in the correct way, combining literals and variables:
Code:
TF_InsertLine("!settings.ini","31",31,"SettingsManager.floatSet GSDefaultLatencyCompensation 0.0" . ping . "0000")
TF_InsertLine("!settings.ini","32",32,"SettingsManager.U32Set GSInterpolationTime " . ping)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2010, 10:23 pm 
Offline

Joined: May 15th, 2009, 2:40 am
Posts: 15
Oh thanks for the help ruespe...lots less code that way.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 26th, 2010, 6:51 pm 
Offline

Joined: August 17th, 2009, 4:59 am
Posts: 131
Is there a TF function that can remove duplicate or matching groups of lines? For example, could it find and remove the red below, but not the orange?

Code:
QT: test 1
test 1
here
QT: test 2
test 2
here and
here
QT: test 3
test 3
here
QT: test 1
test 1
here

QT: test 4
test 4

(edited for clarity)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2010, 8:11 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Not exactly, with with a bit of pre- and postprocessing you could:

Code:
var=
(join`r`n
QT: test 1
test 1
here
QT: test 2
test 2
here and
here
QT: test 3
test 3
here
QT: test 1
test 1
here
QT: test 4
test 4
)

stringreplace, var, var, `r`n, |||, all ; remove all lines breaks
stringreplace, var, var, QT:, `r`nQT:, all ; now put them back in on the QT: lines, that way we have one line per QT section which we can check for duplicates :wink:
var:=TF_RemoveDuplicateLines(var) ; remove duplicates
stringreplace, var, var, `n, , all ; get red of the new lines
stringreplace, var, var, |||, `n, all ; put them back in
MsgBox % Var
Either this or probably a convoluted regex(replace) with some backreferencing magic :shock:

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


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 ... 6, 7, 8, 9, 10, 11, 12, 13  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Stigg 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