Watching:

Using Find and Replace


show more Using Find and Replace provides you with in-depth training on Web. Taught by James Williamson as part of the Dreamweaver CS3 Beyond the Basics show less
please wait ...

Using Find and Replace

One of the most underused features in Dreamweaver is the Find and Replace feature. Although it can certainly look for and replace specific text, it is in reality much more powerful than that. So in this video we will take a look at the Find and Replace feature and some of the options that surround our different searches and replacing criteria. We are going to work from the index.htm file. So if you are following along in the exercises with me, you want to open index.htm from the Chapter 1 Start folder. Before we get into our Find and Replace, I just want to point something out here on the page. If we look at our sidebar-- I will scroll over to see the sidebar and I will scroll down just a little bit. You will notice that we have a couple of icons that aren't showing up. The reason for that-- if I click inside one of those headings here, I can see that there is -- if I look down at my Tag Selector down here in the lower left hand corner, we can see that the class crawl has been applied to the Heading 2 tag. Well, the class should actually be music and not crawl. We could certainly go back and edit our tag so that it was music instead or even rewrite the Selector, but maybe we were using that Selector all throughout our site. Even without opening up the other pages, we know that every single page in this particular folder has crawl on it instead of music.

So we need to make a very global change, and we are going to use Find and Replace to help us do that. So we find and replace by going to up to our menu and going to Edit and choosing Find and Replace, and of course you can see the shortcut key for that. That would be Command+F or Ctrl+F. The Find and Replace dialog box comes up. I am just going to move this up a little bit so that it's centered a little bit better. Now, we can find text in our current document. If I grab the pulldown menu here, notice that we can search in a lot of different places. We can look in just Selected Text, the Current Document, any Open Documents, we can point to a specific Folder, Selected Files in Site, or even Entire Current Local Site, so that would do a site-wide Find and Replace for you. Now, there are different types of searches available to us. Most people just kind of focus on text, finding one word and replacing it with another. My last name, for example, is Williamson, but for some reason people have trouble with the 'on' and they always just type in Williams. So I have to do find and replaces, where I am replacing Williams with Williamson. This would be what you would use for that. You would use text and it would search just text in it, really wouldn't look inside any of the tags or any of the code. Well, if I grab my pulldown menu, notice that I can get a Source Code, which allows me to actually enter in XHTML code or any type of code that I want, and it would look for that specific code and replace it with another one. We have an Advanced Text feature, and this one is kind of neat, because we can look for specific text. So given my example, Williamson for example, I could type in, Find Williams. Somebody misspelled it inside of a tag, and notice that I can look inside of a tag or not inside of a tag. But if I look at inside of a tag, I can actually specify which tag. Maybe I want to look and find Williams every time it's in h1 tag, and then I could replace that with Williamson. I can actually add these different attributes and things to my tag. So I could actually say, look inside of a tag h1 that has an attribute, and I could say class =, and I can even do like author or however my site was identifying myself, and I can do that. I can just keep adding these. So you can get more and more specific with an Advanced Text search, which is really nice. Now, the last type and the one we are going to use is Specific Tag. Now, I really like Specific Tag because it allows me to edit my site in a very fast and efficient manner, without having to do a lot of manual typing. So in this case, you can search for a Specific Tag, or beside that I can actually type in the tag, or if I grab the pulldown menu, notice that I have my full Tag Library menu here, so I could go down and search for certain tag, like a heading 1 or a div tag. Also, this nice little wildcard right here that says any tag. So I know that in the pages that we are looking at, that the crawl class should have been changed to the music class, no matter where you find it. It might be in a heading 2 in one section, it might be in a paragraph tag in another one. Again, we have a lot of different modifications that we can make to this. We can do With Attribute, Without Attribute, Containing or Not Containing. So you see you can get really, really specific with this. So I am going to say With Attribute, and I will choose class = crawl, and that matches the criteria of what we are looking for. We are looking for any tag throughout our document that has the class crawl applied to it. Now, after you find it and it says, what action do you want to take, we can do lot of different actions. We can replace the Tag and its Contents. We can Strip out and Replace just the Contents of the tag. So you can see from this list, there's a lot of different things here. What we are going to do is we are going to actually set that Attribute. So we are going to change the class attribute from crawl to another attribute. So I am going to choose Set Attribute, and once again, I want to set the class attribute and this time I am going to change it to music rather than crawl. Now, I am doing this in the current document even though I need to do it throughout my entire site. The reason I am doing that is because I want to make sure that what I am doing works properly prior to actually going in and doing this site-wide. So instead of hitting Replace or Replace All, I am going to hit the Find Next icon here in the upper right hand corner. It's actually going to scroll and find this and you may actually-- the Find and Replace menu is actually kind of in the way. So if I move this, I can see right there that its highlighted in that particular heading. Once I have found it, if I hit Replace, I can see probably quickly and easily whether it worked or not, and again, it sort of jumped up to my next one, so I have to look down there toward the bottom. I see the 8.03 now actually does have that change made to it. So if I hit Replace All, it's going to go ahead and replace all of those. I actually get a Results panel that comes up and it lets me know exactly how many of these were replaced on the page. So once you commit to a search, you are going to get a report from Dreamweaver about that. I am just going to go ahead and close that results. Now, if I scroll down to my Sidebar, you can see that now all the Sidebar items have an icon on it. So the search actually worked exactly the way I wanted it to. Of course, I wanted to do this for my whole site, and that was just doing it for that page. So let's go take a look at something else we can do with the Find and Replace. I am going to go back up to Edit and choose Find and Replace. Now, I will go back to a specific tag. Now, it happens to remember the last search that you did, which is wonderful, because it goes ahead and repopulates this, so I didn't have to type this again. But what if I was doing this a day later or a week later? Well, I would probably have to type all this again. So one of the things that I can do is I can save any query that I have got. So right over here in the upper right hand corner is the Save Query icon. I am going to go ahead and click that. I can type this in and I can save this as crawlToMusic.

Just again a descriptive name of the search and what it's going to do. It's going to swap out all crawlsToMusic. Now, you can save this query anywhere that you want. So I probably want to save this in a very specific location, and you might want to keep all your queries in the same place. So I am going to go ahead and expand this out, and once again, I am going to go to James, and I will go my Documents. If you remember, earlier we made a folder in an earlier movie called Dreamweaver Backups. So I am going to create another new folder in my Documents, and I am just going to call this queries, and I will just save it directly inside that. So now the next time I come in here, if I need to, I can go to Load Query, Browse out and find that and load that up. So pretty easy to do actually. So we go into my Documents, queries. If you preview it like this, you can see its just XML. So at a certain point you could make your own if you wanted to just by hand-coding them, if you understood the structure of them. So it's loaded that, and this time I am going to change my Find in from Current Document, and I am just going to grab the pulldown menu here, and I am going to choose Selected Files in Site. Instead of trying to do everything all at once, what I will do is I will just come over here to my Files panel and I will just highlight the pages that I need it to go in and do that search for. So you will notice I am ignoring the index page, and I am sort of getting all the other HTML pages inside there. Since I know that the query works, I am just going to hit Replace All, and Dreamweaver gives me a message that says, these files aren't currently open, and so you can't undo the search, or you sure you want do this? So that's definitely something you want to be absolutely certain of before you click OK on. I am going to go ahead and click Yes, and it's going to perform that change for me. So I will close the Results panel. So now let's go and see how our Find and Replace did for us. So I am going to open up, let's say, shows.htm down here, and again, if I look at my Sidebar-- There we go. My Sidebar now has all of my music icons on there, just the way I wanted them. So it went ahead and performed that change for me. Now imagine how much time we just saved rather than having to go into each file individually and change those classes out by hand. So Find and Replace can really automate a lot of the processes and maintenance that you have to do on a day-to-day basis. Now that we have examined some of the basic features of Find and Replace, our next movie will focus on making our queries more powerful by adding regular expressions to the mix.

Using Find and Replace
Video duration: 9m 50s 11h 10m Intermediate

Viewers:

Using Find and Replace provides you with in-depth training on Web. Taught by James Williamson as part of the Dreamweaver CS3 Beyond the Basics

Subject:
Web
Software:
Dreamweaver
Author:
please wait ...