Jump to content

Split text in a file


jorgev
 Share

Recommended Posts

Hello all,

I'm looking for a way to split a textfile i want to read and display the contens in 3 different edit windows.

The content of the file are actually 3 seperate files that i merged.

And inside the file I added a line like "-----end of part 1-----" and "------end of part 2-------"

I did that to be able to split the files again. But now i'm not sure how i have to do that.

The code i have to start is this:

Case $Buttonloadsetup
    $var2 = FileOpenDialog( "Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2)
    $File = FileOpen ( $var2 , 0 )
     GUICtrlSetData ( $Edit1 , FileRead ( $File ) ) 
     FileClose ( $File );close the file
     $File = FileOpen ( $var2 , 0 ) 
     GUICtrlSetData ( $Edit11 , FileRead ( $File ) ) 
     FileClose ( $File )
     $File = FileOpen ( $var2 , 0 ) 
     GUICtrlSetData ( $EditC , FileRead ( $File ) ) 
     FileClose ( $File )

Offcours this just reads the complete file and displays that file in each edit window($Edit1, $Edit11, $EditC)

Can anyone point me to a methode how i can read until "-----end of part 1-----" and write that to $Edit1,

then read further until "-----end of part 2-----" and write that to $Edit11,

and then read until the end of the file and write that to $EditC

Any help with this would be much appriciated.

kind regards,

Jorgev

Link to comment
Share on other sites

Something like this I think ?

Case $Buttonloadsetup
    $var2 = FileOpenDialog( "Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2)
    $File = FileOpen ( $var2 , 0 )
     $Data = FileRead($File)
     FileClose ( $File );close the file  
     
     GUICtrlSetData ( $Edit1 , StringMid($Data,1,StringInStr($Data,"-----end of part 1-----")) )
     GUICtrlSetData ( $Edit11 , StringMid($Data,StringInStr($Data,"-----end of part 1-----")),StringInStr($Data,"-----end of part 2-----")) )
     GUICtrlSetData ( $EditC , StringMid($Data,StringInStr($Data,"-----end of part 2-----")),StringInStr($Data,"-----end of part 3-----")) )

Edit: extra code was in there

Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

Something like this I think ?

Case $Buttonloadsetup
    $var2 = FileOpenDialog( "Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2)
    $File = FileOpen ( $var2 , 0 )
     $Data = FileRead($File)
     FileClose ( $File );close the file  
     
     GUICtrlSetData ( $Edit1 , StringMid($Data,1,StringInStr($Data,"-----end of part 1-----")) )
     GUICtrlSetData ( $Edit11 , StringMid($Data,StringInStr($Data,"-----end of part 1-----")),StringInStr($Data,"-----end of part 2-----")) )
     GUICtrlSetData ( $EditC , StringMid($Data,StringInStr($Data,"-----end of part 2-----")),StringInStr($Data,"-----end of part 3-----")) )

Edit: extra code was in there

I think that is close, but you will include the separator at th estart, and the length of the stringmid is not calculated correctly.

Maybe this

Case $Buttonloadsetup
    $var2 = FileOpenDialog("Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2)
    $allText = FileRead($var2)

    $start = 1
    $End = StringInStr($allText, "-----end of part 1-----")
    GUICtrlSetData($Edit1, StringMid($allText, $start, $End - $start)

    $start = $End + StringLen("-----end of part 1-----")
    $End = StringInStr($allText, "-----end of part 2-----")
    GUICtrlSetData($Edit11, StringMid($allText, $start, $End - $start)

    $start = $End + StringLen("-----end of part 2-----")
    $End = StringInStr($allText, "-----end of part 3-----")
    GUICtrlSetData($EditC, StringMid($allText, $start, $End - $start)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I think that is close, but you will include the separator at th estart, and the length of the stringmid is not calculated correctly.

Maybe this

Case $Buttonloadsetup
    $var2 = FileOpenDialog("Choose a setup.", $MyDocsFolder, "Rfini (*.RFI)", 2)
    $allText = FileRead($var2)

    $start = 1
    $End = StringInStr($allText, "-----end of part 1-----")
    GUICtrlSetData($Edit1, StringMid($allText, $start, $End - $start)

    $start = $End + StringLen("-----end of part 1-----")
    $End = StringInStr($allText, "-----end of part 2-----")
    GUICtrlSetData($Edit11, StringMid($allText, $start, $End - $start)

    $start = $End + StringLen("-----end of part 2-----")
    $End = StringInStr($allText, "-----end of part 3-----")
    GUICtrlSetData($EditC, StringMid($allText, $start, $End - $start)
That worked like a charm Martin, tx alot

i just had to add ) at the end of each GUICtrlSetData line.

Thanks Martin and ofLight for the input.

Cheers

jorgev

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...