2 Replies - 1109 Views - Last Post: 05 April 2012 - 09:50 PM Rate Topic: -----

#1 deepakgopikannan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-March 12

How to compare 2 strings in a word document (with special character)?

Posted 04 April 2012 - 12:30 AM


I need to compare two strings in a word document i work it out for alphabetic and numeric values but it is not able to compare a string which contains some special characters like (Máceres-Cartínez) Here a and i is occur with special character so it is not compare.

My code is given below.

  StreamReader sr = new StreamReader(this.textBox1.Text);
                string strValue = sr.ReadToEnd();
                string[] strSpliter =new string[1];
                strSpliter[0] = "References";
                string[] strSplitValue = strValue.Split(strSpliter, StringSplitOptions.None);
                String[] strParaValue = strSplitValue[1].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                FileStream fst = new FileStream(@"E:\TrueText.txt",FileMode.Append);
                StreamWriter swt = new StreamWriter(fst);
                FileStream fsf = new FileStream(@"E:\FalseText.txt", FileMode.Append);
                StreamWriter swf = new StreamWriter(fsf);

                swt.WriteLine("Startred on :" + DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss") + "\n");
                swf.WriteLine("Startred on :" + DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss") + "\n");

                foreach (string strPara in strParaValue)
                {
                    string[] strAuthorsPart = strPara.Split('.');
                    string[] strAuthorslist = strAuthorsPart[0].Split(',');
                    string[] strAuthor = strAuthorslist[0].Split(' ');
                    if (strSplitValue[0].Contains(strAuthor[0].Trim()))
                    {
                        swt.WriteLine(strAuthor[0] + "\t");
                    }
                    else
                    {

                        swf.WriteLine(strAuthor[0] + "\t");
                    }
                    //foreach (string strAuthorName in strAuthorslist)
                    //{
                    //    string[] strAuthor = strAuthorName.Trim().Split(' ');
                    //    if (strSplitValue[0].Contains(strAuthor[0]))
                    //    {
                    //        swt.WriteLine(strAuthor[0] + "\t");
                    //    }
                    //    else
                    //    {

                    //        swf.WriteLine(strAuthor[0] + "\t");
                    //    }
                    //}
                    swt.WriteLine("\r\n");
                    swf.WriteLine("\r\n");
                    swt.Flush();
                    swf.Flush();
                }






Did any one guide me how to resolve this?


Thanks
Deego

Is This A Good Question/Topic? 0
  • +

Replies To: How to compare 2 strings in a word document (with special character)?

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 138
  • View blog
  • Posts: 840
  • Joined: 21-December 11

Re: How to compare 2 strings in a word document (with special character)?

Posted 05 April 2012 - 05:42 AM

I suggest you to try this: use IndexOf function to see if string contains string, and try to change string comparsion method.
string str="leo messi, maradona, ronaldo";
string str2 = "ronaldo";
int index = str.IndexOf( str2,StringComparison.Ordinal);
if (index != -1)
{
// string contains 'ronaldo'
}
else
{
// string doesn't contains 'ronaldo'
}

Try also 'OrdinalIgnoreCase'.
You can find all string comparison members here
Was This Post Helpful? 0
  • +
  • -

#3 deepakgopikannan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-March 12

Re: How to compare 2 strings in a word document (with special character)?

Posted 05 April 2012 - 09:50 PM



Yes your response too correct but here what my question is in word document datum i have a string which contains the alphabets like á,í,ä for this type of occurance the string comparison is not working properly. Please give any suggestion how to compare this types of data?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1