The Artima Developer Community
Sponsored Link

C# Answers Forum
C# Text Replacement

3 replies on 1 page. Most recent reply: Sep 19, 2003 3:03 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Ben

Posts: 2
Nickname: nolege
Registered: Sep, 2003

C# Text Replacement Posted: Sep 17, 2003 3:09 PM
Reply to this message Reply
Advertisement
I am looking for a way to replace text in a txt file from a console application -- beginner -- Here is an example
----------------------------------------------------------
Hi Jane,

Just wanted to get a reimbursement from you for the dinner when you told me you didn't want to see me again. If you could send $35.00 to the following address. Thanks and have a nice life.

Jow Blow
1234 Highland
Sacramento CA, 87987

Jow Blow
----------------------------------------------------------
I want the program to replace Jane with the user input, replace Joe Blow with the user input, and the address, amount etc..

Any help would be appreciated thanks..


krs1

Posts: 4
Nickname: krs1
Registered: Sep, 2003

Re: C# Text Replacement Posted: Sep 17, 2003 5:34 PM
Reply to this message Reply
You can use the regular expression library in System.Text.RegularExpressions. Regex.Replace() as well as string.Replace() should do what you need. Both should do a find/replace for the specified string (or pattern in the case of Regex.)

-Kris

Ben

Posts: 2
Nickname: nolege
Registered: Sep, 2003

Re: C# Text Replacement Posted: Sep 18, 2003 5:33 PM
Reply to this message Reply
I can't get the 'using system.text.regularexpression' to compile. The is a 'using System.text' but not a replace function?? can you help elaborate. sorry I'm a beginner

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: C# Text Replacement Posted: Sep 19, 2003 3:03 PM
Reply to this message Reply
It would be even simpler to create a template that looks like this:


Dearest, Loviest {0},

Just wanted to send you a reimbursement for the dinner
when my former pal happened by and mentioned my wife and
thirteen half-witted children. Please find enclosed a
money order for ${1}. Don't worry, the welt on my cheek
is barely noticeable any more.

{2}ly yours,

{3}
{4}
{5}

{3}


Then you just use string.Format(), like this:


string letter = string.Format( letterTemplate, recipient, mealPrice,
signoff, sender, senderSt, senderLocation );


Of course, you can configure the granularity of information as you choose.

Flat View: This topic has 3 replies on 1 page
Topic: Persistence and Polymorphic Reads Previous Topic   Next Topic Topic: Object Type Compile Time Type Checking

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use