none
email body string.replace not working consistantly RRS feed

  • Question

  • in a custom ribbon add-in, I have the below method that when called will replace a given value with ""

    however it only works sometimes

    when it fails it gives no errors, it just does not remove the text at all

    Can someone tell me what I am doing wrong here?

    or give me a better way of doing this?

    public static void removeStartBody(Outlook.MailItem mail, string strPassRemoveValue)
            {
                try
                {
                   mail.Body = mail.Body.Replace(strPassRemoveValue, "");
                }
                catch (Exception ex)
                {
                  MessageBox.Show("ERROR: " + ex.Message);
                }
            }


    • Edited by niyack Wednesday, November 28, 2012 4:05 PM
    Wednesday, November 28, 2012 3:59 PM

Answers

  • //sometimes its safe to parse the data to avoid inconsistencies
    public static void removeStartBody(Outlook.MailItem mail, string strPassRemoveValue)
            {
                try
                {
                   string oBody = mail.Body;
                   oBody = oBody.Replace(strPassRemoveValue,"");
                   mail.Body = oBody;
                }
                catch (Exception ex)
                {
                  MessageBox.Show("ERROR: " + ex.Message);
                }
            }


    Thursday, November 29, 2012 12:39 AM

All replies

  • when do you invoke this code and what is bodyformat of that mail?
    Wednesday, November 28, 2012 7:42 PM
  • //sometimes its safe to parse the data to avoid inconsistencies
    public static void removeStartBody(Outlook.MailItem mail, string strPassRemoveValue)
            {
                try
                {
                   string oBody = mail.Body;
                   oBody = oBody.Replace(strPassRemoveValue,"");
                   mail.Body = oBody;
                }
                catch (Exception ex)
                {
                  MessageBox.Show("ERROR: " + ex.Message);
                }
            }


    Thursday, November 29, 2012 12:39 AM