xilace Posted November 4, 2012 Share Posted November 4, 2012 I have a feeling that i'm simply WAY over complicating this. What i'm trying to do is find a phrase in a txt/ini file, once found replace the entire line with what i want. Example: Look for "ResX=" (in this case i dont know what would be after the "ResX="), and replace the entire line with what i want such as "ResX=1024". I tried doing it with the ini read/write section, but when i write it, it erases all the other keys in the section if i dont declare them as well. I have also tried the filewritetoline, but while i can find the character position in the file using stringinstr, i dont know what line its on to replace it. This is just same random things i was trying and failing at. $WillowEngineFile = (@UserProfileDir & "\Documents\My Games\Borderlands 2\WillowGame\Config\WillowEngine.ini") $OriginaliniFile = FileRead($WillowEngineFile) $resx = StringInStr($OriginaliniFile, "ResX=") $resy = StringInStr($OriginaliniFile, "ResY=") StringReplace($OriginaliniFile, "ResX=", "ResX=1024") FileWrite($WillowEngineFile, $OriginaliniFile) Link to comment Share on other sites More sharing options...
caleb41610 Posted November 4, 2012 Share Posted November 4, 2012 Look at IniRead() and IniWrite() It should immediately answer all your questions. Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
xilace Posted November 4, 2012 Author Share Posted November 4, 2012 While i would agree I'v gone over them as stated above several times, although when a section has lets say 20 keys and i only want to change 1 or 2, it erases the other 18 and will only show the ones i changed. Is there something i'm missing that allows me to save the other 18 that arent being changed? Link to comment Share on other sites More sharing options...
caleb41610 Posted November 4, 2012 Share Posted November 4, 2012 While i would agree I'v gone over them as stated above several times, although when a section has lets say 20 keys and i only want to change 1 or 2, it erases the other 18 and will only show the ones i changed. Is there something i'm missing that allows me to save the other 18 that arent being changed?IniRead()StringReplace()IniWrite()I didn't read your entire post at first. just use string replace on the old data and re-write it Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
xilace Posted November 4, 2012 Author Share Posted November 4, 2012 Even though i dont know what the entire sting will be? it could be ResX=0, ResX=44, anything really after the = sign. Link to comment Share on other sites More sharing options...
caleb41610 Posted November 4, 2012 Share Posted November 4, 2012 If ResX is the only thing you are trying to replace you should be able to change only that key with IniWrite()... can you post the ini?and post what code you used that "erases the other 18" ? Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
PhoenixXL Posted November 4, 2012 Share Posted November 4, 2012 (edited) Example - Replaces every ResX= with ResX= 1024 [Leaves rest of the File untouched]Code;The File Local $nFile = @ScriptDir & 'Testing.txt' ;Read the File Local $sRead = FileRead($nFile) ;The string to append with Local $sWith = '1024' ;Our Pattern Local $sPattern = '(?m)(?:^.*)(ResX=)(?:.*$)' ;Replace the Strings and get the result Local $sReplaced = StringRegExpReplace($sRead, $sPattern, '123 '&$sWith&@CR) ConsoleWrite($sReplaced) ;Again write it back to the file Local $hFile = FileOpen($nFile,2) FileWrite($hFile,$sReplaced)The TextFiledqwrvxcvwh dqeSvnukResX=fweyb ResX=qe4135ResX=sfggr Resf=greyh qqggResX= Edited November 4, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. 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