1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/// <summary>
/// Determines whether the specified text is an palindrome.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="CaseSensitive">if set to <c>true</c> [case sensitive].</param>
/// <returns>
/// <c>true</c> if the specified text is an palindrome; otherwise, <c>false</c>.
/// </returns>
public static bool IsPalindrome(string text, bool CaseSensitive)
{
if (String.IsNullOrEmpty(text))
return false;
int textLength = text.Length -1;
int halfTextLength = textLength / 2;
if (!CaseSensitive)
text = text.ToLower();
for (int i = 0; i <= halfTextLength; i++)
{
if (text[i] != text[textLength])
return false;
textLength--;
}
return true;
}
|