Files
SammelmappeOOP/Stringaufgabe2/Analyse.cs
2024-07-25 15:47:46 +02:00

63 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace Stringaufgabe2
{
internal class Analyse
{
private string? _string;
private char[] konsonant = new char[] { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' };
private char[] umlaut = new char[] { 'ä', 'ö', 'ü', 'ß' };
private char[] vokal = new char[] { 'a', 'e', 'i', 'o', 'u' };
private char[] zeichen = new char[] { '.',',',';',':','-','*','#', '+','?','`','´','^','%','!' };
private char[] zahlen = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
private int _vokal;
private int _konsonant;
private int _umlaut;
private int _zeichen;
private int _zahlen;
private int _rest;
public void AnalyseString(string s)
{
this._string = s.ToLower();
for (int i = 0; i < _string.Length; i++)
{
if (vokal.Contains(_string[i]))
{
_vokal++;
}
else if (umlaut.Contains(_string[i]))
{
_umlaut++;
}
else if (konsonant.Contains(_string[i]))
{
_konsonant++;
}
else if (zeichen.Contains(_string[i]))
{
_zeichen++;
}
else if (zahlen.Contains(_string[i]))
{
_zahlen++;
}
else
{
_rest++;
}
}
Console.WriteLine($"Der Text hat: {_konsonant} Konsonante");
Console.WriteLine($" {_vokal} Vokale");
Console.WriteLine($" {_umlaut} Umlaute");
Console.WriteLine($" {_zeichen} Zeichen");
Console.WriteLine($" {_zahlen} Zahlen");
Console.WriteLine($" {_rest} Leerzeichen");
}
}
}