Jump to content

Recommended Posts

Hi,

What do you think is the problem with my snippet below? I cannot replace the string in my text file, though I can read its position.

Thanks!

_FileReadToArray( $file, $FileArray)

    For $a = 1 To $FileArray[0]
        If StringInStr($FileArray[$a], 'AdScanEndSts') Then
            $Replaced = StringReplace( FileReadLine($filepath, $a), 'AdScanEndSts', 'AdScanEndSts1' )
            _FileWriteToLine( $filepath, $a, $Replaced, 1 )
            MsgBox(0, "",$Replaced)
        EndIf
    Next

 

Here is my txt file:

/********************************/
/*    スタティック変数定義        */
/********************************/
static volatile UB AdScanEndSts ;                                                /* VSG01: ADスキャン完了状態    */


/****************************************/
/*    物理対応仮想チャネルテーブル        */
/****************************************/
static volatile const UB AdPhy2VcTbl[ AD_CH_MAX ] = AD_VC_TBL ;                    /* 物理⇒仮想変換table            */

 

 

Share this post


Link to post
Share on other sites

Maybe its locked by another process or maybe its encoding, did you use FileOpen and not close the file.  The following worked fine for me:

#include <File.au3>
$filepath = @ScriptDir & "\Filename.txt"
Local $FileArray
_FileReadToArray( $filepath, $FileArray)
    For $a = 1 To $FileArray[0]
        If StringInStr($FileArray[$a], 'AdScanEndSts') Then
            $Replaced = StringReplace( FileReadLine($filepath, $a), 'AdScanEndSts', 'AdScanEndSts1' )
            _FileWriteToLine( $filepath, $a, $Replaced, 1 )
            MsgBox(0, "",$Replaced)
        EndIf
    Next

 

Share this post


Link to post
Share on other sites

I tried to put the sample text file in the same path where au3 file was stored, the code works. So, I think the problem is how I defined the path of my file.

 

Local $filepath = StringTrimRight(ControlGetText( "ソフトウェア単体テスト自動化ツール D-SPIDER  Ver.1.0.0", "", "WindowsForms10.EDIT.app.0.1ca0192_r11_ad11" ), 21)

_FileReadToArray( $filepath & "/" & "ad_drv.c", $FileArray)

 

$filepath was extracted from a third party application

image.png.bc01a1730fc97813634543e982c242f3.png

Is there anything wrong with my approach?

Edited by CiaronJohn

Share this post


Link to post
Share on other sites
1 hour ago, Subz said:

Maybe its locked by another process or maybe its encoding, did you use FileOpen and not close the file.  The following worked fine for me:

#include <File.au3>
$filepath = @ScriptDir & "\Filename.txt"
Local $FileArray
_FileReadToArray( $filepath, $FileArray)
    For $a = 1 To $FileArray[0]
        If StringInStr($FileArray[$a], 'AdScanEndSts') Then
            $Replaced = StringReplace( FileReadLine($filepath, $a), 'AdScanEndSts', 'AdScanEndSts1' )
            _FileWriteToLine( $filepath, $a, $Replaced, 1 )
            MsgBox(0, "",$Replaced)
        EndIf
    Next

 

I tried to put the sample text file in the same path where au3 file was stored, the code works. So, I think the problem is how I defined the path of my file.

 

Local $filepath = StringTrimRight(ControlGetText( "ソフトウェア単体テスト自動化ツール D-SPIDER  Ver.1.0.0", "", "WindowsForms10.EDIT.app.0.1ca0192_r11_ad11" ), 21)

_FileReadToArray( $filepath & "/" & "ad_drv.c", $FileArray)

 

$filepath was extracted from a third party application

image.png.bc01a1730fc97813634543e982c242f3.png

Is there anything wrong with my approach?

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...