Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 5th, 2007, 09:24 PM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Find&Replace

Hello Everyone,

I have a question regarding the use of Find&Replace Function....


I'm using a Find&Replace script technique to insert code snipets into an Webpage.aspx

e.g. By Entering a Unique (Keyword) and then Replace with the (Code Snipnet).

Now this all seems to work Fine. But the problem I started noticing, is that as the Wedpage grows insize because I am always adding new (datagrid Code to it)with the additional volume (code Snipets) being always added. That it takes longer and longer for the Find&Replace to Work.


Is there a way to get The Find&Replace to go Directly to the
(Keywords)
instead of Searching thru all of the Codes being

added? (or) Start Searching From the Top of the Webpage first???
Is there someway to Optimize the Find&Replace Solution? Ideally I't would be nice if it could Find the

(Keywords) straight away, instead of combing thru everything...and using up precious time. Any insight would be Appreciated. Thank You.

 
Old June 6th, 2007, 07:50 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This is what a search and replace does. It's how it works. How do you expect for the search to find something if it doesn't go thru everything?? That's the whole point. Do you know where the keywords are already? Can you navigate to them?

I have not found that search and replace is slow in Visual Studio (I assume that is what you are asking about, you have not specified). Perhaps your code files are getting too big and you could break apart functionality to keep the individual files smaller.

Is it possible that you have the search settings set to search all files or all open documents instead of just the current document? Searching thru other files would be noticeably slower.

-Peter
 
Old June 6th, 2007, 09:29 AM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello planoie,

        Let me explain about the Webpage use, The Datagrid being added to the Webpage is for different clients, each DataGrid contains infomation unique for that client only. Now instead of always having to manually adding new Datagrids to the Webpage as needed. I have written a FindnReplace Code to run and automatically add the new Datagrid as necessary, using certain (keyword) with the FindnReplace code. Now with 1-10 clients on the Webpage it works extremely fast and efficient. I noticed as the Webpage grows in size the efficiency starts to bog down...This is Not Good... So hence my dilemma. I was hoping for a some kind of solution to get the FindnReplace technique to somehow go directly to the (Keywords), Or Read from the Top of the Webpage. The (Keywords) I have been using are TextWords. Would it make any difference if I changed the Keywords to Somekind of Unique (Sysbols)=$$~~$$) instead ???
If only there were a way to keep the FindnReplace Code from having to read thru Everything - somehow to block it and only read what you want it to read. This is where my thoughts are. I'm not sure if this is possible??? Here is my Replace Code snipet. . . If you can think of Something that would be great. . .Thank You.

__________________________________________________ __________________________________________________ ___________________________________________

void btnReplace_Click(object sender, EventArgs e) {



                    txtReplace.Text = txtContents.Text;

                     txtFound.Text ="";
                    if(CheckEmpty())
                    {
                        DirectoryInfo DI= new DirectoryInfo(txtFolder.Text);
                        if(DI.Exists)
                        {
                            int FileCount=0;
                            lstFound.Items.Clear();
                            foreach(FileInfo FI in DI.GetFiles())
                            {
                                if(FI.Extension==txtFileExt.Text || txtFileExt.Text=="" ||txtFileExt.Text=="*.*")
                                {
                                    try
                                    {
                                        StreamReader SR= new StreamReader(FI.OpenRead());
                                        String s;
                                        String temp="";
                                        int pos=0;
                                        s=SR.ReadLine();
                                        while(s!=null)
                                        {
                                            temp=temp+s+"\r\n";
                                            s=SR.ReadLine();

                                        }
                                        temp=temp.Substring(0,temp.Length-2);
                                        SR.Close();


                                         if(temp.IndexOf(txtFind.Text)>=0)
                                        {

                                            pos=temp.IndexOf(txtFind.Text);
                                            //txtFound.Text =txtFound.Text +FI.Name + " Char:"+pos+System.Environment.NewLine;
                                            lstFound.Items.Add(FI.Name + " Char:"+pos+System.Environment.NewLine);
                                            //MessageBox.Show("temp:"+temp+ " "+"txtFind:"+txtFind.Text+" txtReplace:"+txtRep lace.Text);

                                            temp=temp.Replace(txtFind.Text,txtReplace.Text = txtContents.Text.Trim());
                                            //MessageBox.Show("temp: "+temp);
                                            FI.Delete();
                                            StreamWriter SW= new StreamWriter(FI.OpenWrite());
                                            SW.Write(temp);
                                            SW.Close();
                                            FileCount++;

                                        }


                                    }
                                    catch(Exception)
                                    {
                                        MessageBoxShow.Text = ("Error opening file!");
                                    }
                                }

                            } // Foreach Loop Ends Here
                            txtFound.Text =txtFound.Text + "Replace Completed Successfully..."+System.Environment.NewLine + "No of Occurences :" +FileCount;
                        } // IF Loop Ends Here
                        else
                            MessageBoxShow.Text = ("Please enter a valid directory path!");
                    }
 
Old June 6th, 2007, 09:40 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Why not build the application flexible so that you can change the client configuration instead of essentially reprogramming it? This sounds like more of a fundamental design problem. Perhaps you need to rethink how the application is built.

Can you explain a bit more about the variation from client to client? Are you creating multiple instances of the same application for different clients? Is this one application that have client context switching? It's is not obvious what solution to provide without some additional information.

Regarding the performance of the search: I think you are stuck with what you have. Simply put, a search searches everything within the file, character by character. No matter how you slice and dice the file contents, you still have to go thru all the lines and all the chars to find anything. But based on my previous comment, there may very well be a much more programmatically elegant, efficient and configurable way to build the application that may likely eliminate all this searching and replacing.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace 2 characters at once!! HELP scovitch65 VB.NET 2002/2003 Basics 2 March 18th, 2006 01:40 AM
find and replace code zabsmarty General .NET 0 March 15th, 2006 10:39 PM
Find and replace? Stuart Stalker SQL Server 2000 8 October 13th, 2005 02:49 AM
Create a find and a find and replace in VB.NET snowy0 VB How-To 0 January 26th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.