Jump to content

FIND REPLACE FOR TEXT FILES


sathish
 Share

Recommended Posts

Hi Forum

My question may be silly,

Is there any way to create a Wizard like Find, replace Options available in Scite Editor

My need is I have to use my own FIND, REPLACE for whatever text editor i use,

I hope you guys understood my question

Please suggest

Thanks in advance

Link to comment
Share on other sites

For Example, i have attached a text file ss.txt here

In this file i need to find the first <ref>...</ref> using the find wizard, and after that i will replace with some texts

Then i need to find next <ref>..</ref> and goes on

But i should not use the native find replace window, i need to create a window like that which performs the actions in the Active window

ss.txt

Link to comment
Share on other sites

StringRegExp

StringRegExpReplace

Regex: (?i)(?:<[s*]{0,1}i?[^>]*)ref>(.*)[^s*]{0,1}[?:^<]

you will have to take care of the whitespaces or someone expert in regex might help you with a regex which handles whitespaces .

This is the best I can do.

Regards

Deltarocked

Link to comment
Share on other sites

StringRegExp

StringRegExpReplace

Regex: (?i)(?:<[s*]{0,1}i?[^>]*)ref>(.*)[^s*]{0,1}[?:^<]

you will have to take care of the whitespaces or someone expert in regex might help you with a regex which handles whitespaces .

This is the best I can do.

Regards

Deltarocked

I think you misunderstood, i know the REGEX very well, but the thing is the FIND REPLACE window

I need to create a FIND REPLACE Window from which i can customize my FIND and REPLACES

I need to create my own FIND REPLACE WINDOW for text files

Link to comment
Share on other sites

Here is the attached text file

My requirement is to open the ss.txt in the editor and FIND REPLACE the text

Please check the attached image

In "FIND REF" button the text <ref>(.*?)</ref> have to be founded one by one and In the "APPLY-STYLE" button <refss>(.*?)</refs> should be replaced

It should be carried one by one

If the user clicks FIND REF, it should find first <ref>(.*?)</ref> and if the user clicks "APPLY-STYLE" button <refss>(.*?)</refs> should be replaced, if the user clicks FIND REF, without clicking APPLY-STYLE, it should not replace, instead of replacing it should find the next <ref>(.*?)</ref>

Sorry for my bad English, hope u guys understood my requirement

#include <Misc.au3>
#include <File.au3>
#include <String.au3>
#include <GUIEdit.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $data, $original
Global $file

If $cmdLine[0] > 0 Then
    If $cmdLine[1] <> "" Then
        $file = $cmdLine[1]
    EndIf
EndIf

If $file <> "" Then
    FileOpen($file,0)
    If @error = -1 Then
        MsgBox(48,"Error","Could not open the file.")
    EndIf
    $data = FileRead($file)
    $original = $data
    If @error = 1 Then
        MsgBox(48,"Error","Could not read the file contents.")
    EndIf
EndIf
#EndRegion ### End Startup Checks ###


HotKeySet("^o","_Open")

#Region ### START Koda GUI section ### Form=
$frmTextEditor = GUICreate("Sample Text Editor (STE)", 720, 435, -1, -1)
$txtEdit = _GUICtrlEdit_Create($frmTextEditor,"", 0, 0, 720, 435, BitOr($ES_MULTILINE,$ES_WANTRETURN, $ES_AUTOVSCROLL))

GUICtrlSetResizing(-1,102)
$mnuFile = GUICtrlCreateMenu("&File")
$mnuOpen = GUICtrlCreateMenuItem("&Open", $mnuFile)
$mnuSave = GUICtrlCreateMenuItem("&Save", $mnuFile)
$mnuSaveAs = GUICtrlCreateMenuItem("Save As...", $mnuFile)
$div = GUICtrlCreateMenuItem("",$mnuFile)
$mnuExit = GUICtrlCreateMenuItem("&Exit", $mnuFile)


$mnuFile1 = GUICtrlCreateMenu("&Edit")
$mnuOpen1 = GUICtrlCreateMenuItem("&REF- STYLE APPLY", $mnuFile1)
$mnuSave1 = GUICtrlCreateMenuItem("&Save", $mnuFile1)
$mnuSaveAs1 = GUICtrlCreateMenuItem("Save As...", $mnuFile1)
$div1 = GUICtrlCreateMenuItem("",$mnuFile1)
$mnuExit1 = GUICtrlCreateMenuItem("&Exit", $mnuFile1)


#EndRegion ### END Koda GUI section ###

_GUICtrlEdit_SetText($txtEdit,$data)
GUISetState()

#Region ### Main body of program ###
While 1
    If _IsPressed("11") = 1 And _IsPressed("53") = 1 Then
        _Save(_GUICtrlEdit_GetText($txtEdit))
    EndIf
    If _IsPressed("11") = 1 And _IsPressed("41") = 1 Then
        _GUICtrlEdit_SetSel($txtEdit,0,-1)
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $mnuOpen
            _Open()
        Case $mnuSave
            _Save(_GUICtrlEdit_GetText($txtEdit))
        Case $mnuSaveAs
            $file = FileSaveDialog("Select file.",@WorkingDir,"text files (*.txt) | All files (*.*)",16)
            _Save(_GUICtrlEdit_GetText($txtEdit))
        Case $mnuExit
            
        Case $mnuOpen1
            #include <ButtonConstants.au3>
            #include <GUIConstantsEx.au3>
            #include <WindowsConstants.au3>
            
            #Region ### START Koda GUI section ### Form=
            $Form1 = GUICreate("REF-STYLE APPLIER", 417, 76, 225, 287)
            $Button1 = GUICtrlCreateButton("FIND REF", 40, 16, 147, 49, 0)
            $Button2 = GUICtrlCreateButton("APPLY-STYLE", 232, 14, 147, 49, 0)
            GUISetState(@SW_SHOW)
            #EndRegion ### END Koda GUI section ###
            
            While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
            Case $GUI_EVENT_CLOSE
            Exit
            
            
        Case $button1
            


    EndSwitch
WEnd

            

        
            
            
            
    EndSwitch
    Sleep(20)
WEnd
#EndRegion ### End the main body ###

#Region ### Custom Functions ###
Func _Open()
    $file = FileOpenDialog("Open",@WorkingDir,"text (*.txt)| all (*.*)")
    If @error = 1 Then
        MsgBox(48,"Error", "Could not open file or no file selected.")
    Else
        $data = FileRead($file)
        _GUICtrlEdit_SetText($txtEdit,$data)
    EndIf
EndFunc

Func _Save($sData)
    FileClose($file)
    FileOpen($file,2)
    If @error = -1 Then
        MsgBox(48,"Error","File could not be written to.")
    EndIf
    FileWrite($file,$sData)
    If @error = 1 Then
        MsgBox(48,"Error","Could not write file contents.")
    EndIf
    $original = $sData
EndFunc

Func _Exit()
    If _GUICtrlEdit_GetText($txtEdit) <> $original Then
    $ask = MsgBox(35,"Save?","Save changes to file?")
        If $ask = 6 Then
            _Save(_GUICtrlEdit_GetText($txtEdit))
            Exit
        ElseIf $ask = 7 Then
            Exit
        Else
        
        EndIf
    Else
        Exit
    EndIf
EndFunc
#EndRegion ### End Custom Functions ###

ss.txt

post-69004-0-00420700-1334916653_thumb.j

Link to comment
Share on other sites

HI sathish,

from what I have understood : You want to selectively ensure the replacement values.

My question :

Why do you want to create a GUI text editor when the same task can be done using

1: Sanitize the file by stripping all unwanted linefeeds

2: Ensure that each line contains exactly one entry

then reading the line displaying the line and then going ahead with the logic of stingreplace. The output would be stored in a secondary file.

Hope this helps.

Regards

Deltarocked.

[EDIT]

between two post of yours there should be someone elses post . otherwise its considered *Bumping* and I think its against the rules of the forum.

Consider using the *edit* like I have done in this post

Edited by deltarocked
Link to comment
Share on other sites

HI sathish,

from what I have understood : You want to selectively ensure the replacement values.

My question :

Why do you want to create a GUI text editor when the same task can be done using

1: Sanitize the file by stripping all unwanted linefeeds

2: Ensure that each line contains exactly one entry

then reading the line displaying the line and then going ahead with the logic of stingreplace. The output would be stored in a secondary file.

Hope this helps.

Regards

Deltarocked.

[EDIT]

between two post of yours there should be someone elses post . otherwise its considered *Bumping* and I think its against the rules of the forum.

Consider using the *edit* like I have done in this post

Thanks for your kind reply

The need for these type of GUI text editor (With Find REPLACE Capabality) is follows:

This tool is going to be used by my staffs (Non - Software), they need to check the replacements one by one as it happens,

And also this will be a new and challenging concept for me to develop,

I need to know, whether this is possible to create like this, if so please guide me,

Thanks & Regards

help needed

Edited by sathish
Link to comment
Share on other sites

  • 1 month later...

Hi Satish,

Learn from this or use this.

[EDIT]

gnuwin32.sourceforge.net/packages/gsar.htm

I have used this to modify sql files with sizes ranging from 20 kb to 1 GB.

rgds

deltarocked.

Thanks for the reply,

I gone through that,

That is quite different from my need, it uses the host text editor's FIND REPLACE,

But the thing i am asking is, to create a FIND REPLACE Dialog, in our own text editor,

Kindly suggest me is it possible

Thanks in Advance

Link to comment
Share on other sites

yes it is possible.

I was hoping that by now you might have read my previous posts carefully and would have completed your task. but it seems to me you are looking for someone who will code it for you.

the answer for your query lies in my previous post - #7.

rgds

delta

Link to comment
Share on other sites

yes it is possible.

I was hoping that by now you might have read my previous posts carefully and would have completed your task. but it seems to me you are looking for someone who will code it for you.

the answer for your query lies in my previous post - #7.

rgds

delta

Thanks for the reply,

From the beginning of my post, i am asking just, whether this is possible or not??? only,

I never wanted some one to code for me, (I dont like it too)

Thanks & Regards

Sathish V.

Link to comment
Share on other sites

How did you create your text editor? Is it an AutoIt-script with GUICtrlCreateEdit? Create a simple GUI with the input window and FIND / NEXT buttons. Then read the text, get the current selection and begin your search with the selection end as the offset . Select the next occurence and scroll it into the viewport.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 1 month later...

How did you create your text editor? Is it an AutoIt-script with GUICtrlCreateEdit? Create a simple GUI with the input window and FIND / NEXT buttons. Then read the text, get the current selection and begin your search with the selection end as the offset . Select the next occurence and scroll it into the viewport.

Sorry for the late reply

Yes through Autoit Script only (text editor)

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...