replace the text after some text.

Hi friends,

I had a word file. it contains some text. in the text i need to replace text after the tag name (<name>).

 for eg  the document file contains the text like this

<name>XXXX

but i need to change the text "XXXX" to "YYYYY"

<name>YYYYY

The <name> is same in all word file which i have, but the names after the <name> are different.

object nullobj = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
            Microsoft.Office.Interop.Word.Document dmtDoc;
            object file = DMTPath;
            dmtDoc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
            string m_Content = dmtDoc.Content.Text;
            wordApp.Selection.Find.ClearFormatting();
            wordApp.Selection.Find.Replacement.ClearFormatting();
            wordApp.Selection.Find.Text = findtext;
            bool check = wordApp.Selection.Find.Execute(ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref  nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
            wordApp.Documents.Close(ref nullobj, ref nullobj, ref nullobj);

I opened the file and find the text <name> is present or not. if present i need to change the text.

i did not know how to change the text after finding the tag <name>.

Thanks in Advance,

 

 

 


Thanks & Regards,
B.Vidhyashri.,
0
vidhyashri
12/25/2008 6:43:58 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

10 Replies
1068 Views

Similar Articles

[PageSpeed] 33

 you can use regular expression for finding and replacing patterns..

sample:

str = "<name>toreplace";

str = Regex.Replace(str, @"<name>\w+", "<name>new string");


The real voyage of discovery consists not in making new landscapes, but in having new eyes
0
sreejukg
12/25/2008 9:15:26 AM

 You could use the HTML Agility pack from http://www.codeplex.com/htmlagilitypack


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
0
TATWORTH
12/28/2008 8:24:25 PM

This word file contains the text like this.

sdfdfrtert wtwrtwt wtwtrwrt  wtwtwtwtr  wtwtwrtwtwt

wrwwerw wwtwt wwtw wtwtw wtwtwtw wtwetw 

<name>XXXX

wrwr wtwrtw wtwt wtwtwt wstwst wtwtwt wtwt 

I need to change the text after <name>.


Thanks & Regards,
B.Vidhyashri.,
0
vidhyashri
12/30/2008 8:17:01 AM

try the regex replace suggested by sreejukg

Regex.Replace(str, @"<name>\w+", "<name>new string");


Jerry Joseph
IT Consultant

Microsoft Certified Technology Specialist in .NET Framework 2.0 Web Applications

View Jerry Joseph's profile on LinkedIn


~ Please Mark as Answer if it solves your query ~
0
jerryjoseph
12/30/2008 8:54:14 AM

i found RegexStringValidator --its a class. i am uanble to find Regex. any namespace i need to add?

 

 

 


Thanks & Regards,
B.Vidhyashri.,
0
vidhyashri
12/30/2008 9:24:48 AM

Hi VidhyaShri, 

Regex is a class in the "System.Text.RegularExpressions" namespace.


"Mark as Answer"
-- on the post that helps you

RKChaudary
0
rkchaudary
12/30/2008 10:07:34 AM

If i tried to  change <name> XXXX YYYYY ZZZZZZ  to  <name> AAAA using

Regex.Replace(str, @"<name>\w+", "<name>new string");

It displays <name> AAAA YYYYY ZZZZZZ  instead of  <name> AAAA .

 


Thanks & Regards,
B.Vidhyashri.,
0
vidhyashri
12/30/2008 10:37:24 AM

 use the charecter class for this

String str = "<name>tor-eplace 123";
 str = Regex.Replace(str, @"<name>[\w\s-]+", "<name>new string"); 

in between [] you put all the characters that may come in your string.. \w - any word character, \s space character.. - hyphen


The real voyage of discovery consists not in making new landscapes, but in having new eyes
0
sreejukg
12/30/2008 12:33:51 PM

Hi friends,

When i try to replace the

 <name>aaaa bbbb

sample word for next line

I used Regex.Replace(str, @"<name>[\w\s\w]+", "<name>xxxx yyyyy"); 

It replaced correctly but it displays like this <name>xxxx yyyyy sample word for next line .

The "sample word for next line" should be in next line. but it displays in the same line.

Thanks in advance,


Thanks & Regards,
B.Vidhyashri.,
0
vidhyashri
1/6/2009 4:58:44 AM

Hi,

use new line character at the end like

Regex.Replace(str,@"<name>[\w\s\w]+","<name>xxxx yyyyy \n"); 

look at the new line character "\n" not sure about the new line char used in word doc. replace it with corresponding char.


"Mark as Answer"
-- on the post that helps you

RKChaudary
0
rkchaudary
1/19/2009 6:23:41 AM
Reply:

Similar Artilces:

How do I get the Text of a Text ....
That may sound confusing, but I need to get the text of a Dynamically created text object. For each row the Text objects text might be somthing different, and when I loop through all the rows, I need to see if any of them are a certain Word. When I used Getitemstring, it doesn't like it. dw_1.Describe( 'text_control.text' ) will give you the .text attribute of a text control in a datawindow. How are you getting different values for the .text attributes on different rows? Using an expression or something? -- Paul Horan[TeamSybase] VCI Springfield, MA www.v...

length or trim ? how can i get textbox.text as text that publichouse to textbox.text as text that public ?
hello friends length or trim ? how can i get textbox.text as text that publichouse to textbox.text as text that public ? second example is ..... textbox1.text is greenhouse.. i want to get green from textbox.text cheer Mark as me if my question or my answer can be helpful for you :) Hi,you can always perform a Trim to a retrieved string to delete the leading and trailing space characters. For your second example where you want to gt a part of the retrieved string you can use the SubString method of the String class.Grz, Kris. Read my blog. Handy Firefox plugins for web developers.Workar...

Text as text
Name: JohnA Boice Email: jaboiceathughesdotnet Product: Firefox Summary: Text as text Comments: You need to do as Safari does and make ALL text, including buttons, links, bookmarks, and general page text actual text so screen readers can interpret and voice the text. Until this occurs, your products are a real pain to use. And I have limited sight. What about those with less or no sight? Browser Details: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 ...

DOM, how to get text out of text node
Hi all, i am stack on this: i am parsing a dom document, i reach a text node, but i can't get the text out of the text node. Hope some one can help. this is the code: childs is a nsIDOMNodeList. PRUint32 len, i; childs->GetLength( &len ); nsCOMPtr<nsIDOMNode> child; nsEmbedString name; nsEmbedString value; PRUint16 type; for( i = 0; i < len; i++ ) { childs->Item( i, getter_AddRefs( child ) ); child->GetNodeType( &type ); child->GetLocalName( name ); ...

Copy web text fr FF2 PASTE to outlook text mail msg get an attachment not text
I never had this problem with IE. When I copy text from a web page and try to paste it as text into an Outlook2000 TEXT mail message, it instead is rendered into an attachment to the message. I just want to paste the text. Does anyone know why this happens, better yet - how to fix it? Currently I have to past the text into a text editor, and then recopy that into my Outlook mail message. This is getting old fast. Thanks in advance. Sandalls On 2/23/2007 5:01 PM On a whim, Sandalls pounded out on the keyboard > I never had this problem with IE. > > When I co...

Text not appearing when typing the text into text field
Name: Maadhavan Email: madhavan_t_patyahoodotcom Product: Firefox Summary: Text not appearing when typing the text into text field Comments: Text not appearing when typing the text into text field or any other field Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.9) Gecko/2009040821 Firefox/3.0.9 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

Bold Text For Selected text in Text Box
Hi EveryoneI have a small thing to do [at this time , very big for me]. I want to make some text string as bold which appears in a text box control for the web. It means some of the portion of the string will be bold and some will be in the normal font style. Can anyone suggest any idea to accomplish this task. [I know that we can set the font weight property for the whole text box and all the text appears in the selected font-weight]Any suggestions.BaberBaber SaeedSoftware EngineerPalmChip, Pakistan Toll Free: 0800-000-13 Ext:494Cell: 0300-6438634 Standard TextBox that comes with ASP.NET ...

Getting Text Between Two Words In Text File
Hi everyone, Im just wondering what the best way to do this would be.I need to get a certain line of text from a number of text file records.This text lies between "-" and a </strong> tag. How would I go about this Thanks for your help! julie Use the File class to open and read your file and then use Regular Expression to find the specific word. References: File Class Regular Expression "I refuse to sign my posts with some clever quote said by some famous tech head in order to make myself seem more intelligent"-- Bill Gates...

How do I get the left part of a text box.text
How do I get the left part of a text box.text???Something like: textbox1.text.left(3) to get 'abc' if the text box contains the alphabeth.But then the correct way You can do something as: string mainString = "abcdefg....";string strSubString = mainString.SubString(0,2); Hope this helps, RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP Use the Substring() method.string tempstring = TextBox1.Text.Substring(0,3); thanks all...

How to get a text from rich text edit control ?
It does not have a such property as 'Text'. So how can I catch in to variable whatever user types ? Thanks. string ls_text this.SelectTextAll() ls_text = this.SelectedText() On Thu, 24 May 2001 11:43:44 -0400, in powersoft.public.powerbuilder.general yt <tyuriy@aol.com> wrote: >It does not have a such property as 'Text'. So how can I catch in to >variable whatever user types ? > >Thanks. > > Bruce Armstrong [TeamSybase] http://www.needhim.org ---== Posted via the PFCGuide Web Newsreader ==--- http://www.pfcguide.com/_news...

How does text gets displayed in composer text field?
Hi, I'm new to TB dev. I stumbled upon this problem while trying to fix bug 309= 708. I am trying to figure out how does a message gets displayed in the com= poser window? I noticed that when I click edit on a mail in my drafts folde= r, the text in the uncompleted mail is displayed in the composer. I want to= do something similar to this. Does anyone know how does TB copy the text from the mail and display it on = the composer window? Is there like a textField.setText() to put the text into the composer's edi= ting text field? In another words, what function should i ca...

How to get plain text of currently displayed text
I need to get text of currently displayed page from extension. var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var mainWindow = wm.getMostRecentWindow("navigator:browser"); alert(mainWindow.getBrowser().selectedBrowser.contentDocument.getSelection().toString()) This returns only selected text. I need to get all text content but has no glue how to do this. Please help. Alex On Dec 17, 5:15=A0am, dzen <dze...@inbox.ru> wrote: > I need ...

Getting evaluated text value for text objects
I'm attempting to get the visible text value out of a text object in a report. If I describe the .Text attribute, I can get the text out, however, if the value is an expression I get the unevaluated string. I can describe the Evaluate function called with the .Text attribute as the argument, and this will normally return the evaluated text from the element. The problem I have encountered is when you have, for example, a field named "phone" and the text value of the text element is also the word "phone". Calling evaluate on this will replace the word &quo...

Replacing the HeaderRow texts and SelectButton texts in a DataGrid
I have a DataGrid with allowSorting = True The HeaderRow displays the column names from the database which you click on to sort by that column. I want to replace the texts to something more user friendly than my database column names. If I do DataGrid.HeaderRow.Cells(1).Text = "..." the hyperlink javascript:__doPostback disappears and you are no longer able to sort by this column. Does anyone have an example on how to replace the texts in the header row without breaking the hyperlinks. I also have AutogenerateSelectButton = True where I want to replace the text select with something els...

Web resources about - replace the text after some text. - asp.net.getting-started

File:Replace this image male.svg - Wikipedia, the free encyclopedia
to an image (e.g. you photographed or drew it yourself) and would like Wikipedia to use it, you must release it under a free copyright license ...

Facebook Replaces Payments Emails With API
Facebook announced that it is scrapping the emails that it sends to developers containing information about payments , replacing it with a payments ...

Facebook’s New Ads Power Editor Replaces the Bulk Uploader with a Streamlined GUI
This week, Facebook launched its new Ads Power Editor desktop software for buyers who work directly with a Facebook ads representatives. The ...

Face Morph HD - Change and Replace Head in Pic Frame Hole with Pencil Portrait Effects! on the App Store ...
Get Face Morph HD - Change and Replace Head in Pic Frame Hole with Pencil Portrait Effects! on the App Store. See screenshots and ratings, and ...

NASA just chose SpaceX to replace the Shuttle for flying astronauts
jurvetson posted a photo: Elon's design goal = "the safest, most advanced crew vehicle ever flown.” With seats for seven . First manned flight ...

How to replace Roland Juno 106 Voice Chip 80017A 1 of 2 - YouTube
Own a Juno 106? You might encounter a dying voice chip. In this 2 part vid series I explain how to fix this problem. Don't be afraid its really ...

Khurram Khan ‘is going to be very difficult to replace’ for UAE ahead of World Twenty20 qualifiers
The post-Khurram era starts when the UAE face the hosts Scotland in the opening fixture of the World Twenty20 qualifier. The national team have ...

Change of the Day: Canadian Town Wants to Replace Its ‘Land of Rape & Honey’ Motto
The town of Tisdale in Saskatchewan has had a very unfortunate slogan for the past 60 years, and they’re finally looking for a new one. Visitors ...

ASI helps Cloud wholesaler replace Cisco hardware with Brocade rentals
ARNnet ASI helps Cloud wholesaler replace Cisco hardware with Brocade rentals ARNnet Cloud Plus is transitioning from Cisco to Brocade hardware ...

Notable names floated to replace Georgie Gardner on Today
Two names have raised eyebrows within television circles as Channel Nine prepares to announce a replacement newsreader on its breakfast television ...

Resources last updated: 12/29/2015 2:09:22 PM