0

I have some strings in different languages; for example:

  • "kot jest dobry" (in Polish)
  • "cat is good" (in English)

They are captions of buttons that are translated from English to the language chosen from the user.

Which is the best way to compare these captions, programmatically?

Mansfield
  • 14,445
  • 18
  • 76
  • 112
Bublik
  • 912
  • 5
  • 15
  • 30
  • 4
    Compare them to what? You want to compare the English string to the Polish string? – zmbq Jun 05 '12 at 09:41
  • 1
    please make your problem more clear – Maziar Aboualizadehbehbahani Jun 05 '12 at 09:42
  • yes, i want to compare two localized strings. in code I have "cat is good" which depending of language, at run time it is shown at polish or another language, and set as a object caption. i want to get this caption and compere it with string, i dont know in whitch langueage it is, because it is set by user at program runtime – Bublik Jun 05 '12 at 09:53
  • @user1224225: the probability of equivalence of two strings, when they are localized on different languages, are very closer to zero. Work in code with resources and don't care about current language. Let the runtime manage your resources. – Dennis Jun 05 '12 at 10:00
  • but the not equal if i compare them using "==" or string.compare function – Bublik Jun 05 '12 at 10:03
  • moreover, i using devexpress, localization: http://documentation.devexpress.com/#WindowsForms/CustomDocument1866 – Bublik Jun 05 '12 at 10:12

2 Answers2

1

Since both the strings are translations of one another you can maintain a translation table and if you want to find out if two strings are same you can just look them up in your table and if they happen to fall in the same row, then they are equal for example

class TranslatedText
{
      public int Id {get; set; }
      public string Language {get; set; }
      public string Text {get; set; }
}

So populate a list of TranslatedText objects with each string and assign same id to same pieces of text. Later to compare you can lookup the corresponding object in list and check the Id like so

var first = translatedTextList.FirstOrDefault(t=>t.Text.Equals(firstString));
var second = translatedTextList.FirstOrDefault(t=>t.Text.Equals(secondString));
bool areSame = (first != null & second !=null & first.Id == second.Id);
return areSame;

Assuming the strings you want to compare are called firstString and secondString;

Muhammad Hasan Khan
  • 34,648
  • 16
  • 88
  • 131
-2

override .equal() function or convert it to char array then compare!

here you find HOW:

http://msdn.microsoft.com/en-us/library/ms173147.aspx