Commit f9fc03e8 authored by Uwe Wienkop's avatar Uwe Wienkop

String-Funtionen Reverse, IstPalindrom

parent 28ea07e7
......@@ -35,16 +35,17 @@ namespace _05Character
string s1 = "Hallo Welt";
Console.WriteLine(ToUpper(s1));
//if (s1 < s2)
s1 = "RELIEFPFEILER";
Console.WriteLine($"Ist {s1} ein Palindrom => {istPalindrom(s1)}");
Console.WriteLine(Reverse("ABCD"));
}
static int CompareTo(string s1, string s2)
{
// 0 --> s1 == s2
// >0 --> s1 > s2
// <0 --> s1 < s2
{
int minZeichen; // Länge der kürzeren Zeichenkette bestimmen
if (s1.Length < s2.Length)
minZeichen = s1.Length;
......@@ -74,9 +75,33 @@ namespace _05Character
if (c >= 'a' && c <= 'z')
sErg += (char) (c - 32); // (char) unbedingt notwendig, sonst
else // werden die Zahlenwerte gespeichert
sErg += c;
sErg = sErg + c;
}
return sErg;
}
static string Reverse(string zeichenkette)
{
string sErg = "";
foreach (char zeichen in zeichenkette)
{
sErg = sErg + zeichen;
}
return sErg;
}
static bool istPalindrom(string s)
{
int i=0, j=s.Length-1;
while (i<j)
{
if (s[i] != s[j])
return false;
i++;
j--;
}
return true;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment