Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:02:54+00:00 2026-06-11T22:02:54+00:00

I want to compare whether two strings are equal or not in C# using

  • 0

I want to compare whether two strings are equal or not in C# using the Equals() method of the string class. But even though both strings are same, my conditional check is failing.

I have seen that both strings are equal and also verified this at the http://text-compare.com/ site. I don’t know what is the issue here…

My code is :

protected string getInnerParaOnly(DocumentFormat.OpenXml.Wordprocessing.Paragraph currPara, string paraText)
        {
            string currInnerText = "";
            bool isChildRun = false;

        XmlDocument xDoc = new XmlDocument();
        xDoc.LoadXml(currPara.OuterXml);
        XmlNode newNode = xDoc.DocumentElement;

        string temp = currPara.OuterXml.ToString().Trim();

        XmlNodeList pNode = xDoc.GetElementsByTagName("w:p");
        for (int i = 0; i < pNode.Count; i++)
        {
            if (i == 0)
            {
                XmlNodeList childList = pNode[i].ChildNodes;
                foreach (XmlNode xNode in childList)
                {
                    if (xNode.Name == "w:r")
                    {
                        XmlNodeList childList1 = xNode.ChildNodes;
                        foreach (XmlNode xNode1 in childList1)
                        {
                            if (xNode1.Name == "w:t" && xNode1.Name != "w:pict")
                            {
                                currInnerText = currInnerText + xNode1.InnerText;
                            }
                        }
                    }
                }
              if (currInnerText.Equals(paraText))
              {
                  //do lot of work here...
              }
   }
}

When I put a break point in and go through step by step, watching each and every character, then there is a difference in currInnerText last index. It looks like an empty char. But I already used the Trim() function. This is the picture captured during the debug process.

What is the solution for removing the empty char or any other spurious characters at the end of the currInnerText string?

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:02:55+00:00Added an answer on June 11, 2026 at 10:02 pm

    Try putting a breakpoint and checking the length. Also, in some cases, if the locale is not the same, the equals function does not result in true. Another method you could try(checking the length) is printing both like this —string1—, —string2—, this way, you could see if you have any trailing spaces. To fix this you can use string1.trim()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compare two strings for equality when either or both can be
Currently, I have two matrixes, and want to compare it and see whether they
I have some string name and I want to compare whether that string contains
I have two strings which I'd like to compare: String and String: . Is
I want to compare a string variable with $city variables in this array using
I want to compare the first few bytes in byte[] with a string. How
I want to compare two CSV files to see if they are different. I
I want to compare two times in VB.net: I have 1:42:21 PM and I
I've got two instances of a PHP5 Class (say ClassA), and I want to
I have a two lists with values that I want to compare. If the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.