473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Replace Text in Dozens of HTML Files

I would appreciate suggestions for a general strategy I could use to update
a bunch of HTML files.

Specifically I need to replace sevaral instances of one string with another
string in each of a few dozen HTML files.

While I already plan to use RegEx to do the actual replacement, what should
I be doing to open, update, and save each of the files. What would be an
efficient way to do this? I'm seeing that .NET has a File class, TextWriter,
StreamWriter, StringBuilder, and on and on. There are so many options. Which
ones would work together and what would make sense for my particular
situation?

Thanks.
Nov 17 '05 #1
1 1457
Jeffrey,

Replacing portions of a string is inherent in all classes that are
string oriented (String, StringBuilder, string, etc.). So if replacing
text is your only requirement, any class will do for that. If you need
to append text, then StringBuilder is a better choice.

Using RegEx is a good choice for finding text but you'll have to do
some performance testing to see whether it outperforms a typical
Replace method in the code you are using it in.

Because you are dealing with HTML files, you have one additional
requirement and that is case-sensitivity. To locate and replace HTML
text means that you need to have a method that is case insensitive,
which is what RegEx is good for. On the other hand, there are things in
HTML files that are case-sensitive and need to maintain their case. If
you simply ignore the case while replacing, you may get undesired
side-effects. So be aware of RegEx when replacing case-sensitive text.

I have written applications that replace a large amount of HTML text
and have used StreamReader and StreamWriter because these classes can
be used by many other classes that are derived from them. TextReader
and TextWriter have limited derivatives.

Johann Blake

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Cortes | last post by:
Hi all, Suppose I want to add 1 single line: <script src = "/sample.js" type="text/javascript"></script> to every single webpage ( preferrably right after the tag <head>) under the root...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
5
by: Usenet User | last post by:
A user informed me that some pages I've created with nested tables are spewing out dozens of blank pages at the end of a print run. No one noticed this for a long time, as printer-friendly files...
23
by: SeaPlusPlus | last post by:
I want to convert large files of prose to xhtml and so I need a way to remove unwanted line wraps. So, I'm looking for a freebee editor that has the capability of searching for a single "carriage...
5
by: Casey | last post by:
Hello, Can someone give me specific code to replace text on a page using server side javascript? I need to use server-side because I need the output to be recognized in the final HTML so that...
3
by: gregpinero | last post by:
Hi guys, What I'm trying to do is find all instances of an acronymn such as IBM on a webpage and replace it with <acronym title="International Business Machines">IBM</acronym>. However in my...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
6
by: DataSmash | last post by:
Hello, I need to search and replace 4 words in a text file. Below is my attempt at it, but this code appends a copy of the text file within itself 4 times. Can someone help me out. Thanks! #...
6
by: Clive Backham | last post by:
I need to set up forms where some input fields are mandatory and others are optional. A common convention is to place an asterisk on the labels of the mandatory fields. Of course, I can just hard...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.