Sorting it all Out Michael Kaplan's random stuff of dubious value Be sure to read the disclaimer here first!
Jonathan Payne asked if I had an international thought about the palindrome pseudo interview question at this site:
http://channel9.msdn.com/ShowPost.aspx?PostID=19171
I did. :-)
Using the new StringInfo stuff in Whidbey Beta 2:
bool IsPalindrome(string st) { StringInfo si = new StringInfo(st); int count = si.LengthInTextElements; if (count == 0) return false; for (int i = 0; i < (count / 2); i++) { string st1 = si.SubstringByTextElements(i, 1); string st2 = si.SubstringByTextElements(count - i - 1, 1); if (CultureInfo.CurrentCulture.CompareInfo.Compare(st1, st2) != 0) { return(false); } } return (true);}
bool IsPalindrome(string st) { StringInfo si = new StringInfo(st); int count = si.LengthInTextElements;
if (count == 0) return false;
for (int i = 0; i < (count / 2); i++) { string st1 = si.SubstringByTextElements(i, 1); string st2 = si.SubstringByTextElements(count - i - 1, 1);
if (CultureInfo.CurrentCulture.CompareInfo.Compare(st1, st2) != 0) { return(false); } }
return (true);}
Quickest way to handle all those cool issues like cultural sensitivity and combining characters and supplementary characters and such!