I’m currently have an issue trying to edit the Text inside my Document.Contents.Text
The following code does not work:
object findingFile = m_TempFileDirectory.FullName + "\\" + formField.Name + ".rtf";
Document tempDoc = wordApp.Documents.Open(ref findingFile, ref m_Missing,
ref m_Missing, ref m_Missing, ref m_Missing, ref m_Missing, ref m_Missing,
ref m_Missing, ref m_Missing, ref m_Missing, ref m_Missing, ref m_Missing,
ref m_Missing, ref m_Missing, ref m_Missing, ref m_Missing);
tempDoc.Content.Select();
String st = tempDoc.Content.Text;
st = st.Replace("\r", "");
tempDoc.Content.Text = st;
tempDoc.Content.Copy();
tempDoc.Close(ref m_DiscardChanges, ref m_Missing, ref m_Missing);
r.Paste();
My outcome is still (I’m trying to remove the \r for New Line)
Lipid level: not specified\r
EDIT
I was wrong about escaping the \r, because of course you are replacing the actual control character (\r), not the literal “\r”‘. Sorry.
You are correct in your comment, when you do
tempDoc.Content.Text = st;a new linefeed (\r) gets appended. You will always need to remove or replace at the time that you actually use the value.It looks like you want to copy the text to the clipboard? If so, why not just do it from the string (
st):I also replaced the linefeeds with carriage-returns (\n), because if you don’t do that there will be no linefeeds in the text at all (a problem if you have multiple lines of text).
(Original answer deleted)