ur Posted September 12, 2016 Share Posted September 12, 2016 Hi, I have a file whose content will be as below. //[publish:include]******************************************************************************** /// \file PSXBuildNumber.h Contains the build number for the entire product suite. /// /// Copyright (c) 2006 CA. All rights reserved /// /// This software and all information contained therein is confidential /// and proprietary and shall not be duplicated, used, disclosed or /// disseminated in any way except as authorized by the applicable /// license agreement, without the express written permission of CA. /// All authorized reproductions must be marked with this language. /// /// EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE /// EXTENT PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE /// WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY /// IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR /// PURPOSE. IN NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY /// THIRD PARTY FOR ANY LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE /// USE OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, LOST PROFITS, /// BUSINESS INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY /// ADVISED OF SUCH LOSS OR DAMAGE. //************************************************************************************************* #define PSX_BUILD_NUMBER 5011 #define PSX_BUILD_NUMBER_STRING "5011" In the above file, if you observe, I have 2 lines where I can see a number 5011. This 5011 is not fixed but my requirement is to replace the number mentioned after PSX_BUILD_NUMBER and PSX_BUILD_NUMBER_STRING with the number I pass in the code. Can you suggest how to do Link to comment Share on other sites More sharing options...
JohnOne Posted September 12, 2016 Share Posted September 12, 2016 StringRegexReplace Ot _StringBetween and StringReplace AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
rcmaehl Posted September 12, 2016 Share Posted September 12, 2016 As @JohnOne stated. StringReplace, possibly setting the 4th parameter ( occurrence ) to the max number of times you want to replace in the file to prevent accidental changes to other parts of the file. My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
ur Posted September 12, 2016 Author Share Posted September 12, 2016 But I don't want to replace only 5011. it should replace whatever the number might be in the two lines with PSX_BUILD_NUMBER_STRING and PSX_BUILD_NUMBER Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 12, 2016 Moderators Share Posted September 12, 2016 @ur are you looking to pass this value in at run-time? Something like this? Local $PSX_BUILD_NUMBER If $CmdLine[0] = "" Then MsgBox(0, "", "You must enter a build number") Else $PSX_BUILD_NUMBER = $CmdLine[1] MsgBox(0, "", $PSX_BUILD_NUMBER) EndIf You would then run the compiled script like this: scriptname.exe <buildnumber> -or- scriptname.exe 1511 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JohnOne Posted September 12, 2016 Share Posted September 12, 2016 3 hours ago, ur said: But I don't want to replace only 5011. it should replace whatever the number might be in the two lines with PSX_BUILD_NUMBER_STRING and PSX_BUILD_NUMBER Either method I mentioned (_stringBetween easier for noob) will get you whatever that number is. Please refer to help file example, and have a go. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AutoBert Posted September 12, 2016 Share Posted September 12, 2016 (edited) This are the 2 solutions i prefer for such a case, 1: #include <File.au3> Global $PSX_BUILD_NUMBER If $CmdLine[0] = "" Then MsgBox(0, "", "You must enter a build number") Exit Else $PSX_BUILD_NUMBER = $CmdLine[1] ;MsgBox(0, "", $PSX_BUILD_NUMBER) EndIf Global $aFile, $sFile='PSXBuildNumber.h' _FileReadToArray($sFile,$aFile) Global $aSplit=StringSplit($aFile[$aFile[0]],' ') Global $sSearch=StringReplace($aSplit[$aSplit[0]],'"','') _ReplaceStringInFile($sFile,$sSearch,$PSX_BUILD_NUMBER) 2: #include <File.au3> Global $PSX_BUILD_NUMBER If $CmdLine[0] = "" Then MsgBox(0, "", "You must enter a build number") Exit Else $PSX_BUILD_NUMBER = $CmdLine[1] ;MsgBox(0, "", $PSX_BUILD_NUMBER) EndIf Global $aFile, $sFile='PSXBuildNumber.h' Global $sData=FileRead($sFile) Global $iPos=StringInStr($sData,' ',0,-1) Global $sSearch=StringMid($sData,$iPos+1) $sSearch=StringReplace($sSearch,'"','') _ReplaceStringInFile($sFile,$sSearch,$PSX_BUILD_NUMBER) note: doing this with one ob both scripts is only possible if last entry in file is the numer or the number in quotes. Edited September 13, 2016 by AutoBert Link to comment Share on other sites More sharing options...
mikell Posted September 13, 2016 Share Posted September 13, 2016 (edited) And what about a SRER ? $s = FileRead("1.txt") $new_val = "1234" $r = StringRegexpReplace($s, '(PSX_BUILD_NUMBER(?:_STRING)?\h*"?)(\d+)', "${1}" & $new_val) Msgbox(0,"", $r) Edit : another flavour w/o backreference $r = StringRegexpReplace($s, 'PSX_BUILD_NUMBER(?:_STRING)?\h*"?\K\d+', $new_val) Edited September 13, 2016 by mikell 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