Jump to content

Recommended Posts

Posted

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

Posted (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 by TheXman
Posted

<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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...