Commit 87bebc70 authored by Uwe Wienkop's avatar Uwe Wienkop

Weitere Stringfunktionen, Caesar-Codierung

parent f9fc03e8
......@@ -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)
{
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DF0C7E25-0F18-4AF4-AF3B-392B076CE690}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_05Felder</RootNamespace>
<AssemblyName>05Felder</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
\ No newline at end of file
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}");
}
}
}
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")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4C41C810-73CE-44DF-9D1C-4A9CCD001F10}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_05StringSpeed</RootNamespace>
<AssemblyName>05StringSpeed</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
\ No newline at end of file
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);
}
}
}
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")]
......@@ -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
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