Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

FIND REPLACE FOR TEXT FILES


  • Please log in to reply
14 replies to this topic

#1 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 20 April 2012 - 07:07 AM

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







#2 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 20 April 2012 - 07:14 AM

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

Attached Files

  • Attached File  ss.txt   693bytes   138 downloads


#3 DeltaRocked

DeltaRocked

    Prodigy

  • Active Members
  • PipPipPip
  • 186 posts

Posted 20 April 2012 - 07:35 AM

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

#4 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 20 April 2012 - 08:30 AM

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

#5 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 20 April 2012 - 10:11 AM

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


AutoIt         
#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 ###  

Attached Thumbnails

  • image.JPG

Attached Files

  • Attached File  ss.txt   673bytes   147 downloads


#6 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 21 April 2012 - 04:06 AM

Please suggest me, whether this task is possible or not????

#7 DeltaRocked

DeltaRocked

    Prodigy

  • Active Members
  • PipPipPip
  • 186 posts

Posted 21 April 2012 - 08:01 AM

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, 21 April 2012 - 08:04 AM.


#8 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 24 April 2012 - 04:51 AM

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, 05 May 2012 - 05:50 AM.


#9 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 25 May 2012 - 04:59 AM

BUMP AFTER ONE MONTH

#10 DeltaRocked

DeltaRocked

    Prodigy

  • Active Members
  • PipPipPip
  • 186 posts

Posted 01 June 2012 - 06:22 AM

Hi Satish,

http://www.autoitscript.com/forum/topic/118172-textreplace/page__fromsearch__1

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.

Edited by deltarocked, 01 June 2012 - 06:39 AM.


#11 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 05 June 2012 - 09:29 AM

Hi Satish,

http://www.autoitscript.com/forum/topic/118172-textreplace/page__fromsearch__1

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

#12 DeltaRocked

DeltaRocked

    Prodigy

  • Active Members
  • PipPipPip
  • 186 posts

Posted 05 June 2012 - 10:59 AM

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

#13 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 09 June 2012 - 07:55 AM

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.

#14 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 09 June 2012 - 10:09 AM

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, 09 June 2012 - 10:11 AM.

*GERMAN* Posted Image [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

#15 sathish

sathish

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 14 July 2012 - 04:49 AM

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)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users