473,587 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to replace a pattern in a html file using C#?

Can any one of you let me know, how can I replace a pattern in an html file using C#?
I have the contents of the html file stored in a string. I just need to replace some of the elements which have a similar pattern?
ex: I have a field {Token = LoanNumber} in the html file.
I just need to replace Loan Number with some text by finding the pattern "{Token=".
Any suggestions are welcome.
Thanks.
--------------------------------
From: Sam Kon

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>dhKFm1WFH0u QqO7+SHFt1A==</Id>
Nov 16 '05 #1
2 2906
Sam,

I would definitely look at regular expressions for this. I don't know
exactly which expression you would use, but you would get the best
performance (probably).

Perhaps someone else can point out which RegEx he would want to use?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Sam Kon via .NET 247" <an*******@dotn et247.com> wrote in message
news:%2******** ************@tk 2msftngp13.phx. gbl...
Can any one of you let me know, how can I replace a pattern in an html file using C#? I have the contents of the html file stored in a string. I just need to replace some of the elements which have a similar pattern? ex: I have a field {Token = LoanNumber} in the html file.
I just need to replace Loan Number with some text by finding the pattern "{Token=". Any suggestions are welcome.
Thanks.
--------------------------------
From: Sam Kon

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>dhKFm1WFH0u QqO7+SHFt1A==</Id>

Nov 16 '05 #2
KG

"Sam Kon via .NET 247" <an*******@dotn et247.com> wrote in message
news:%2******** ************@tk 2msftngp13.phx. gbl...
Can any one of you let me know, how can I replace a pattern in an html file using C#? I have the contents of the html file stored in a string. I just need to replace some of the elements which have a similar pattern? ex: I have a field {Token = LoanNumber} in the html file.
I just need to replace Loan Number with some text by finding the pattern "{Token=". Any suggestions are welcome.
Thanks.
--------------------------------
From: Sam Kon
As Nicholas said, try regex.
RegexLib.com has good examples

http://regexlib.com
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>dhKFm1WFH0u QqO7+SHFt1A==</Id>

Nov 16 '05 #3

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

Similar topics

1
3717
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'
12
8146
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like apostrophes being sent to database. I've tried to...
4
10190
by: Jane Doe | last post by:
Hi, I need to search and replace patterns in web pages, but I can't find a way even after reading the ad hoc chapter in New Rider's "Inside JavaScript". Here's what I want to do: function filter() { var items = new Array("John", "Jane");
2
2417
by: Barnes | last post by:
Hi, Can anyone please tell me how I can use the replace method to replace a character if it occures in more than one textbox without having to write separate function for each textbox. The code below is the basic way to use the replace method but it only allows for one textbox. I'm sure I need a loop in there but I'm not sure how to...
9
2090
by: David P. Donahue | last post by:
I'm using RegExp.Replace(string, string, string) to remove some pieces of large strings. But I seem to be having trouble getting it to match "all characters up to and including xxxxx" (which I thought would be ".*xxxxx" but it's not working). I can get it to match more precise segments no problem, but not "all characters up to and including...
0
3072
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 want to replace all of them. You need to look at it in a case-by-case basis. What can you do? Answer: emacs.
1
9047
by: Michael Yanowitz | last post by:
Hello: I am hoping someone knows if there is an easier way to do this or someone already implemented something that does this, rather than reinventing the wheel: I have been using the string.replace(from_string, to_string, len(string)) to replace names in a file with their IP address. For example, I have definitions file, that looks...
18
2413
by: Umesh | last post by:
Do you have any answer to it? thx.
6
1730
by: alainfri | last post by:
I am not sure if this group is the right place for this question but what I need is as follows. There is a piece of html. Throughout the html there are a lot of <brtags. The task is to replace all these <brtags with \n\r. The replacement must be performed only within <preblocks. I can do this using VBScript in the following way: Option...
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7974
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.