Suppose I am having a particular text in either MSWord or in a RichTextBox. If I select a particular part of the text, I would like to identify all the words given in italics in that particular fragment and convert it into Regular Text and also give them within <i> and </i> tags. Could u pls tell me how it is possible

Identifying Italic Text
Mike Perri
Microsoft.Office.Interop.Word.
_Document wordDoc;Microsoft.Office.Interop.Word.
_Application MSWord = new Microsoft.Office.Interop.Word.Application();MSWord.Selection.Text;
The text which is in italics in this selected text should tagged. Also I am not familiar with the "access of object model thru automation". So it would be very much helpful if u describe the code to be implemented.
John Ericson174499
It's dependent on how you are getting the text in the first place. If you have a RichTextBox control, then you will have to get the formatted text, and then parse it out yourself (I don't know of a freely available RTF document parser that will make this easier for you). If you have a Microsoft Word instance open with the text in it, then you should be able to access the object model through automation (and COM interop), to get the details of whether or not part or all of the text is italicized.
Hope this helps.
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
Gilles Lafreniere
Joseph,
You are already accessing the object model of Word through Automation (as evidenced from the code sample above).
You can get the text in italics by getting the contents of the Selection property on the Application instance that you have. Once you have that, you can cycle through the characters exposed by the Characters property, and then for each character (it is returned as a range, not a character), check the Font property, to see if it is italic.
Also, you need to be careful that you are releasing the references to all of these COM objects that you are calling by making a call to the static ReleaseComObject method on the Marshal class. Every time that you access a property that returns an object, that object has to be released.
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com