From 87bebc707928700caae2ad3d95af9149f2d1b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TH-N=C3=BCrnberg?= Date: Tue, 7 Nov 2017 11:18:21 +0100 Subject: [PATCH] Weitere Stringfunktionen, Caesar-Codierung --- Prog1_WS2017-18/05Character/Program.cs | 39 +++++++++--- Prog1_WS2017-18/05Felder/05Felder.csproj | 60 +++++++++++++++++++ Prog1_WS2017-18/05Felder/App.config | 6 ++ Prog1_WS2017-18/05Felder/Program.cs | 27 +++++++++ .../05Felder/Properties/AssemblyInfo.cs | 36 +++++++++++ .../05StringSpeed/05StringSpeed.csproj | 60 +++++++++++++++++++ Prog1_WS2017-18/05StringSpeed/App.config | 6 ++ Prog1_WS2017-18/05StringSpeed/Program.cs | 26 ++++++++ .../05StringSpeed/Properties/AssemblyInfo.cs | 36 +++++++++++ Prog1_WS2017-18/Prog1_WS2017-18.sln | 15 +++++ 10 files changed, 303 insertions(+), 8 deletions(-) create mode 100644 Prog1_WS2017-18/05Felder/05Felder.csproj create mode 100644 Prog1_WS2017-18/05Felder/App.config create mode 100644 Prog1_WS2017-18/05Felder/Program.cs create mode 100644 Prog1_WS2017-18/05Felder/Properties/AssemblyInfo.cs create mode 100644 Prog1_WS2017-18/05StringSpeed/05StringSpeed.csproj create mode 100644 Prog1_WS2017-18/05StringSpeed/App.config create mode 100644 Prog1_WS2017-18/05StringSpeed/Program.cs create mode 100644 Prog1_WS2017-18/05StringSpeed/Properties/AssemblyInfo.cs diff --git a/Prog1_WS2017-18/05Character/Program.cs b/Prog1_WS2017-18/05Character/Program.cs index 82d642d..c9f2ca5 100644 --- a/Prog1_WS2017-18/05Character/Program.cs +++ b/Prog1_WS2017-18/05Character/Program.cs @@ -11,6 +11,7 @@ namespace _05Character static void Main(string[] args) { string s = "Hallo Welt"; + char z = 'A'; foreach (char c in s) { @@ -39,6 +40,16 @@ namespace _05Character Console.WriteLine($"Ist {s1} ein Palindrom => {istPalindrom(s1)}"); Console.WriteLine(Reverse("ABCD")); + s = "Hallo Welt"; + s = s.Substring(0, 5) + "*****" + s.Substring(6); + Console.WriteLine(s); + + string codiert = CaesarCodierung("CAESAR AN SEINE LEGION: ANGRIFF AUF DIE GALLIER", 6); + Console.WriteLine(codiert); + for (int i = -1; i>-26 ; i--) + { + Console.WriteLine(CaesarCodierung(codiert,i)); + } } static int CompareTo(string s1, string s2) @@ -67,15 +78,15 @@ namespace _05Character return -1; // neg.Erg --> s1 < s2 } - static string ToUpper(string s) + static string ToUpper(string zeichenkette) { string sErg = ""; - foreach (char c in s) + foreach (char zeichen in zeichenkette) { - if (c >= 'a' && c <= 'z') - sErg += (char) (c - 32); // (char) unbedingt notwendig, sonst - else // werden die Zahlenwerte gespeichert - sErg = sErg + c; + if (zeichen >= 'a' && zeichen <= 'z') // Für Kleinbuchstaben: + sErg += (char) (zeichen - ('a'-'A')); // (char) unbedingt notwendig, sonst + else // werden die Zahlenwerte gespeichert + sErg = sErg + zeichen; // Alle anderen Zeichen einfach übernehmen } return sErg; } @@ -85,11 +96,23 @@ namespace _05Character string sErg = ""; foreach (char zeichen in zeichenkette) { - sErg = sErg + zeichen; + sErg = zeichen + sErg; } return sErg; } - + static string CaesarCodierung(string zeichenkette, int n) + { + string sErg = ""; + foreach (char zeichen in zeichenkette) + { + if (zeichen >= 'A' && zeichen <= 'Z') + sErg += (char)(((zeichen - 'A') + n + 26) % 26 + 'A'); + else + sErg += zeichen; + } + return sErg; + } + static bool istPalindrom(string s) { diff --git a/Prog1_WS2017-18/05Felder/05Felder.csproj b/Prog1_WS2017-18/05Felder/05Felder.csproj new file mode 100644 index 0000000..0df8492 --- /dev/null +++ b/Prog1_WS2017-18/05Felder/05Felder.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {DF0C7E25-0F18-4AF4-AF3B-392B076CE690} + Exe + Properties + _05Felder + 05Felder + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Prog1_WS2017-18/05Felder/App.config b/Prog1_WS2017-18/05Felder/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/Prog1_WS2017-18/05Felder/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Prog1_WS2017-18/05Felder/Program.cs b/Prog1_WS2017-18/05Felder/Program.cs new file mode 100644 index 0000000..044507d --- /dev/null +++ b/Prog1_WS2017-18/05Felder/Program.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _05Felder +{ + class Program + { + static void Main(string[] args) + { + // int px0 = 20, py0 = 30; + int[] f = { 10, 20, 30, 45, 50, 15, 5, 20, 25 }; + + int min = f[0]; // FALSCH: min = 0; + foreach (int item in f) + { + if (item < min) + min = item; + } + Console.WriteLine($"Das Minimum beträgt {min}"); + + + } + } +} diff --git a/Prog1_WS2017-18/05Felder/Properties/AssemblyInfo.cs b/Prog1_WS2017-18/05Felder/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2830b71 --- /dev/null +++ b/Prog1_WS2017-18/05Felder/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("05Felder")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("05Felder")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("df0c7e25-0f18-4af4-af3b-392b076ce690")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Prog1_WS2017-18/05StringSpeed/05StringSpeed.csproj b/Prog1_WS2017-18/05StringSpeed/05StringSpeed.csproj new file mode 100644 index 0000000..8a79b76 --- /dev/null +++ b/Prog1_WS2017-18/05StringSpeed/05StringSpeed.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {4C41C810-73CE-44DF-9D1C-4A9CCD001F10} + Exe + Properties + _05StringSpeed + 05StringSpeed + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Prog1_WS2017-18/05StringSpeed/App.config b/Prog1_WS2017-18/05StringSpeed/App.config new file mode 100644 index 0000000..88fa402 --- /dev/null +++ b/Prog1_WS2017-18/05StringSpeed/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Prog1_WS2017-18/05StringSpeed/Program.cs b/Prog1_WS2017-18/05StringSpeed/Program.cs new file mode 100644 index 0000000..18ba252 --- /dev/null +++ b/Prog1_WS2017-18/05StringSpeed/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace _05StringSpeed +{ + class Program + { + static void Main(string[] args) + { + string sErg = ""; + StringBuilder sb = new StringBuilder(""); + DateTime t0 = DateTime.Now; // Aktuelle Uhrzeit speichern + for (int i = 0; i < 5000000; i++) + { + //sErg = sErg + '.'; + sb.Append('.'); + } + Console.WriteLine((DateTime.Now-t0).TotalMilliseconds); + // Von der jetzigen Uhrzeit die Startzeit abziehen + // Console.WriteLine(sErg); + } + } +} diff --git a/Prog1_WS2017-18/05StringSpeed/Properties/AssemblyInfo.cs b/Prog1_WS2017-18/05StringSpeed/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3963951 --- /dev/null +++ b/Prog1_WS2017-18/05StringSpeed/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("05StringSpeed")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("05StringSpeed")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4c41c810-73ce-44df-9d1c-4a9ccd001f10")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Prog1_WS2017-18/Prog1_WS2017-18.sln b/Prog1_WS2017-18/Prog1_WS2017-18.sln index 7705dbe..3d4aa4b 100644 --- a/Prog1_WS2017-18/Prog1_WS2017-18.sln +++ b/Prog1_WS2017-18/Prog1_WS2017-18.sln @@ -42,6 +42,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "04Praktikumstipps", "04Prak EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "05Character", "05Character\05Character.csproj", "{BCEB94CF-A8DE-4E6B-95EE-360E3933825D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "05StringSpeed", "05StringSpeed\05StringSpeed.csproj", "{4C41C810-73CE-44DF-9D1C-4A9CCD001F10}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "05Felder", "05Felder\05Felder.csproj", "{DF0C7E25-0F18-4AF4-AF3B-392B076CE690}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -116,8 +120,19 @@ Global {BCEB94CF-A8DE-4E6B-95EE-360E3933825D}.Debug|Any CPU.Build.0 = Debug|Any CPU {BCEB94CF-A8DE-4E6B-95EE-360E3933825D}.Release|Any CPU.ActiveCfg = Release|Any CPU {BCEB94CF-A8DE-4E6B-95EE-360E3933825D}.Release|Any CPU.Build.0 = Release|Any CPU + {4C41C810-73CE-44DF-9D1C-4A9CCD001F10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C41C810-73CE-44DF-9D1C-4A9CCD001F10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C41C810-73CE-44DF-9D1C-4A9CCD001F10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C41C810-73CE-44DF-9D1C-4A9CCD001F10}.Release|Any CPU.Build.0 = Release|Any CPU + {DF0C7E25-0F18-4AF4-AF3B-392B076CE690}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF0C7E25-0F18-4AF4-AF3B-392B076CE690}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF0C7E25-0F18-4AF4-AF3B-392B076CE690}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF0C7E25-0F18-4AF4-AF3B-392B076CE690}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {DF0C7E25-0F18-4AF4-AF3B-392B076CE690} = {DD66E463-4183-46B2-A475-A587C445E359} + EndGlobalSection EndGlobal -- GitLab