Commit 8308931d authored by Uwe Wienkop's avatar Uwe Wienkop

string-Funktionen

parent 16e46dd0
<?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>{083C94EB-CBE5-4465-B3C4-5286DAD35D14}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_11StringFunktionen</RootNamespace>
<AssemblyName>11StringFunktionen</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 _11StringFunktionen
{
class Program
{
static string ToUpper(string s)
{
string erg = "";
foreach (char zeichen in s)
{
if (zeichen >= 'a' && zeichen <= 'z')
erg += (char)(zeichen - ('a'-'A'));
else
erg += zeichen;
}
return erg;
}
private static int[] CharAnzahlen(string text)
{
int[] anzahlen = new int[26];
foreach (char zeichen in text)
{
if (zeichen >= 'A' && zeichen <= 'Z')
anzahlen[zeichen - 'A']++;
}
return anzahlen;
}
static int AnzahlVokale(string s)
{
int anzVok = 0;
foreach (char zeichen in s)
{
if (zeichen == 'A' || zeichen == 'E' || zeichen == 'I' || zeichen == 'O' || zeichen == 'U')
anzVok++;
}
return anzVok;
}
static int AnzahlVokale2(string s)
{
int anzVok = 0;
string vokale = "aeiouAEIOU";
foreach (char zeichen in s)
{
foreach (char vokal in vokale)
{
if (vokal == zeichen)
{
anzVok++;
break; // bricht die innere Schleife ab
}
}
}
return anzVok;
}
static int AnzahlWoerter(string s)
{
bool istLeerzeichen = true;
int anzahlWoerter = 0;
foreach (char zeichen in s)
{
if (istLeerzeichen && zeichen != ' ')
anzahlWoerter++;
istLeerzeichen = (zeichen == ' ');
}
return anzahlWoerter;
}
static string StringOhneDoppelteLeerzeichen(string s)
{
bool istLeerzeichen = true;
string erg = "";
foreach (char zeichen in s)
{
if (zeichen == ' ' && istLeerzeichen == false)
erg += zeichen;
else if (zeichen != ' ')
erg += zeichen;
istLeerzeichen = (zeichen == ' ');
}
return erg;
}
static void Histogramm(int[] f)
{
int max = f[0];
for (int i = 1; i < f.Length; i++)
if (f[i] > max)
max = f[i];
// Bis hier: Bestimmung des max. Wasserstands
for (int wasserstand = max; wasserstand > 0; wasserstand--)
{
for (int i = 0; i < f.Length; i++)
Console.Write((f[i] >= wasserstand) ? '*' : ' ');
Console.WriteLine();
}
for (char c = 'A'; c <= 'Z'; c++)
{
Console.Write(c );
}
Console.WriteLine();
}
static void Main(string[] args)
{
string text = "Hallo Du! Wie geht es Dir? Ist es nicht ein wunderbarer Tag?";
Console.WriteLine(ToUpper(text));
int[] f = CharAnzahlen(ToUpper(text));
for (int i = 0; i < 26; i++)
{
Console.WriteLine($"Der Buchstabe {(char) (i+'A')} kommt {f[i]} mal vor");
}
Histogramm(f);
Console.Write($"Der Text enthält {AnzahlVokale(ToUpper(text))} Vokale");
Console.WriteLine($" und {AnzahlWoerter(text)} Wörter");
text = " Dieser Text hat eindeutig zu viele Leerzeichen";
Console.WriteLine($"|{text}|");
Console.WriteLine($"|{StringOhneDoppelteLeerzeichen(text)}|");
}
}
}
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("11StringFunktionen")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("11StringFunktionen")]
[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("083c94eb-cbe5-4465-b3c4-5286dad35d14")]
// 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")]
......@@ -81,6 +81,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "10WortweiseZerlegung", "10W
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "10CallByReference", "10CallByReference\10CallByReference.csproj", "{1A720D7E-A300-4351-9052-B774416A1BE8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11StringFunktionen", "11StringFunktionen\11StringFunktionen.csproj", "{083C94EB-CBE5-4465-B3C4-5286DAD35D14}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -231,6 +233,10 @@ Global
{1A720D7E-A300-4351-9052-B774416A1BE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A720D7E-A300-4351-9052-B774416A1BE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A720D7E-A300-4351-9052-B774416A1BE8}.Release|Any CPU.Build.0 = Release|Any CPU
{083C94EB-CBE5-4465-B3C4-5286DAD35D14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{083C94EB-CBE5-4465-B3C4-5286DAD35D14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{083C94EB-CBE5-4465-B3C4-5286DAD35D14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{083C94EB-CBE5-4465-B3C4-5286DAD35D14}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
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