ijourneaux Posted September 27, 2018 Posted September 27, 2018 I am trying to read a text file and do a string replace on each of the lines. One of the lines in the file is very long (60000 characters) #Include <File.au3> #Include <Array.au3> #include <Misc.au3> lOCAL $aRetArray _FileReadToArray("test.xml", $aRetArray) For $i = 1 To $aRetArray[0] If StringInStr($aRetArray[$i], 'System.Collections.Generic.List`1[System.Single]') Then ConsoleWrite($aRetArray[$i] &@CRLF) $aRetArray[$i] = StringReplace($aRetArray[$i], "System.Collections.Generic.List`1[System.String]", "") ConsoleWrite($aRetArray[$i] &@CRLF) EndIf Next _FileWriteFromArray("test.xml", $aRetArray, 1) @errno after the string replace gives 0. As written the file ends up unchanged. StringInStr correctly identifies the line with the text in it but StringReplace doesn't do the replace. Probaly missing something obvious? Test.xml
TheXman Posted September 27, 2018 Posted September 27, 2018 (edited) I ran it with this and it worked fine. #Include <File.au3> #Include <Array.au3> #include <Misc.au3> Local $aRetArray _FileReadToArray("Test.xml", $aRetArray) For $i = 1 To $aRetArray[0] If StringInStr($aRetArray[$i], 'System.Collections.Generic.List`1[System.Single]') Then ConsoleWrite($aRetArray[$i] &@CRLF) $aRetArray[$i] = StringReplace($aRetArray[$i], 'System.Collections.Generic.List`1[System.Single]', "") ConsoleWrite($aRetArray[$i] &@CRLF) EndIf Next _FileWriteFromArray("Test.new.xml", $aRetArray, 1) Edited September 27, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Malkey Posted September 27, 2018 Posted September 27, 2018 Note: In the first post example. The StringInStr() function is looking for ".....Single]". The StringReplace() function is replacing ".....String]".
ijourneaux Posted September 27, 2018 Author Posted September 27, 2018 <frig> you don't know how many time I had read the string both in the code and in the xml file and didn't see the error. Thank you very much for the extra set of eyes. I
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