gmailuser Posted April 15, 2011 Share Posted April 15, 2011 I am a noob at this I have been doing pretty good so far, but got stuck and cant find solution in the help files. I need a script that will go through a txt file get all the integers after height=" do a math operation to it and then replace it with the result I pretty much got all of it except how to select the integers, any help? Link to comment Share on other sites More sharing options...
sahsanu Posted April 15, 2011 Share Posted April 15, 2011 This is not the best script but in the meanwhile someone gives to you a better solution... Note: list.txt contains: height=100 lalala=jdjdjd line=hsg7 height=text height=200 width=87 #include <file.au3> Global $list=@ScriptDir & "\list.txt" Global $array _FileReadToArray($list,$array) For $i=1 To $array[0] $changeit=StringRegExp($array[$i],"height=(\d+)$",1) if IsArray($changeit) Then $math=$changeit[0] + 1 ;Math operation $array[$i]="height=" & $math EndIf Next _FileWriteFromArray($list,$array,1) Link to comment Share on other sites More sharing options...
gmailuser Posted April 15, 2011 Author Share Posted April 15, 2011 thanks so much, i guess i wasn't thinking about it correctly, i will let you know if i get this to work, thanks for the quick reply man Link to comment Share on other sites More sharing options...
sahsanu Posted April 16, 2011 Share Posted April 16, 2011 thanks so much, i guess i wasn't thinking about it correctly, i will let you know if i get this to work, thanks for the quick reply man Just in case... I've created another script that will change height="xxx" no matter where it is. Warning... I'm so the code is not very elegant . I hope someone could do it easier for you. list.txt contains: height="1"Lorem height="1" ipsum dolor height="2" sit ametheight="3", coheight="3"nsectetur adipiscing elit. Ut tincidunt sagittis laoreet. Nam at viverra fheight="10"elis. Etiam ac accumsan nisi. Aenean lacinia magna et massa congue ac sollicitudin leo pellentesque. Curabitur luctus, velit sagittis fermentum varius, nibhheight="20" mi tempor libero, ut posuere risus diam ac leo. Fusce consectetur nisi eget diam tempus egestas. Curabitur pulvinar varius magna, vel height="30" euismod nisi bibendum vitae. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Aliquam et magna ligula. height="100" Vestibulum egestas pharetra condimentum. Maecenas sed velit vitae augue bibendum posuere vel ac lectus.height="444" #include <file.au3> Global $list=@ScriptDir & "\list.txt" Global $array _FileReadToArray($list,$array) For $i=1 To $array[0] $changeit=StringRegExp($array[$i],'height=\"(\d+)\"',3) if IsArray($changeit) Then For $x=0 To UBound($changeit)-1 $uff=_Math($changeit[$x]) ;Math operation $array[$i]=StringRegExpReplace($array[$i],'height="' & $changeit[$x] & '"','height="' & $uff & '"',1) Next EndIf Next _FileWriteFromArray($list,$array,1) ;will overwrite list.txt file so take care Func _Math($math) $result = $math + 100 Return $result EndFunc Link to comment Share on other sites More sharing options...
gmailuser Posted April 16, 2011 Author Share Posted April 16, 2011 (edited) its cool man i appreciate your help, so this second script would change coheight, ameheight, in the list.txt? im assuming thats the change in string reg exp right? thanks alot man. Edited April 17, 2011 by gmailuser Link to comment Share on other sites More sharing options...
sahsanu Posted April 17, 2011 Share Posted April 17, 2011 (edited) its cool man i appreciate your help, so this second script would change coheight, ameheight, in the list.txt? im assuming thats the change in string reg exp right? thanks alot man.Just try it and you will see what it does one more thing, whats the include file.au3 for?It is an UDF included in autoit standard installation. It's needed to use functions _FileReadToArray & _FileWriteFromArray. Edited April 17, 2011 by sahsanu Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now