C# :: Aufgabe #113
11 Lösungen

Text in Löffelsprache konvertieren
Anfänger - C#
von Veigar
- 16.12.2015 um 19:05 Uhr
Schreibe ein Script welches einen Text entgegen nimmt und ihn in Löffelsprache konvertiert!
(Löffelsprache: "Geheimsprache" die oft von Kindern benutzt wird, und die dadurch gebildet wird das an jeden Vokal (Selbstlaut) „lew" und dann noch einmal der Vokal gehängt wird. zum Beispiel "Ich bin klug!"-->"Ilewich bilewin klulewug!")
(Löffelsprache: "Geheimsprache" die oft von Kindern benutzt wird, und die dadurch gebildet wird das an jeden Vokal (Selbstlaut) „lew" und dann noch einmal der Vokal gehängt wird. zum Beispiel "Ich bin klug!"-->"Ilewich bilewin klulewug!")
Lösungen:
Hier mal eine kleine Lösung.
C#-Code

static void Main(string[] args) { string extension = "lew"; char[] vokale = new char[] { 'e', 'a', 'i', 'o', 'u' }; Console.WriteLine("Bitte geben Sie einen zu verschlüsselnden Text ein:"); string text = Console.ReadLine(); foreach(char v in vokale) { int i=0; while((i=text.ToLower().IndexOf(v,i))!=-1) { text=text.Insert(i+1,extension+v); i += extension.Length + 2; } } Console.WriteLine("\nHier Ihr Text in Löffelchen Sprache:\n"+text); }

using System; using System.Linq; using System.Text; namespace Löffelsprache { class Program { static void Main() { char[] Vokale = new char[] { 'A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u' }; Console.Write("Text>"); StringBuilder sb = new StringBuilder(Console.ReadLine()); for(int i = sb.Length - 1; i > -1; i--) if(Vokale.Contains(sb[i])) sb.Insert(i + 1, GetLew(sb[i])); Console.WriteLine(sb.ToString()); } static string GetLew(char Char) { return "lew" + char.ToLower(Char); } } }

using System; namespace trainYourProgrammer { class MainClass { static void Main(string[] args) { Console.Write ("Satz eingeben: "); string s = Console.ReadLine (); s = s.Replace ("e", "elewe").Replace ("E", "Elewe"); //als erstes ersetzen, weil durch die anderen Ersetzungen neue e's erzeugt werden s = s.Replace ("a", "alewa").Replace ("A", "Alewa"); s = s.Replace ("i", "ilewi").Replace ("I", "Ilewi"); s = s.Replace ("o", "olewo").Replace ("O", "Olewo"); s = s.Replace ("u", "ulewu").Replace ("U", "Ulewu"); Console.WriteLine (s); } } }

using System; using System.Linq; namespace Löffelsprache { class Program { static void Main(string[] args) { string[] vokale = new string[] { "a", "e", "i", "o", "u", "A", "E", "I", "O", "U" }; string ausgabe = ""; Console.WriteLine("Bitte einen Text eingeben, der in Löffelsprache konvertiert werden soll!"); string eingegebenerText = Console.ReadLine(); char[] chararray = eingegebenerText.ToCharArray(); for (int i = 0; i < chararray.Length; i++) { if (vokale.Any((chararray[i]).ToString().Contains)) { ausgabe = ausgabe + chararray[i] + "lew" + chararray[i].ToString().ToLower(); } else { ausgabe = ausgabe + chararray[i]; } } Console.WriteLine(ausgabe); Console.ReadLine(); } } }

public static string PseudoEncrypt(string s) { string Result = ""; foreach (char c in s) Result += ("aeiou".Contains(c)) ? $"{c}lew{c}" : c.ToString(); return Result; } public static string PseudoDecrypt(string s) { string Result = ""; for (int i = 0; i < s.Length; i++) Result += ("aeiou".Contains(s[i])) ? s[i += 4] : s[i]; return Result; }

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Loeffelsprache { class Program { static void Main(string[] args) { Console.WriteLine("Bitte Löffel eingeben (Vokal -> Vokal + Löffel + Vokal):"); String loeffel = Console.ReadLine(); Console.WriteLine("Bitte Text zur Konvertierung in die Löffelspache eingeben:"); String original = Console.ReadLine(); Console.WriteLine(); loeffeln(loeffel, original); Console.ReadKey(); } private static void loeffeln(String loeffel, String original) { char[] Vokal = { 'a', 'e', 'i', 'o', 'u', 'ä', 'ö', 'ü' }; int i1 = 0; StringBuilder loeffelsatz = new StringBuilder(original); while (i1 < loeffelsatz.Length) { for (int i2 = 0; i2 < Vokal.Length; i2++) { if ((Char.ToLower(loeffelsatz[i1])).Equals(Vokal[i2])) { loeffelsatz.Insert(i1 + 1, loeffel + Vokal[i2]); i1 += loeffel.Length + 1; ; break; } } i1++; } Console.WriteLine(loeffelsatz); } } }

static void Main(string[] args) { Console.WriteLine("Bitte geben Sie den zu verschlüsselnden Text ein :\n"); string input = Console.ReadLine(); Console.WriteLine("\nDer verschlüsselte Text lautet:\n\n" + loeffelText(input)); Console.ReadLine(); } static string loeffelText(string text) { string[] vokale = { "e", "a", "i", "o", "u", "E", "A", "I", "O", "U" }; foreach (string v in vokale) { text = text.Replace(v, (v + "lew" + v.ToLower())); } return text; }

public class Program { static void Main() { while (true) { Console.WriteLine("Geben Sie einenen Text ein: "); var tmpResult = ReturnConverted(Console.ReadLine()); Console.WriteLine("Löffelübersetzung: \"" + tmpResult+ "\""); Console.ReadKey(); Console.Clear(); } } /// <summary> /// Gibt den übergebenen Text als Löfelcode zurück /// </summary> public static string ReturnConverted(string inText) { var tmpVokaList = new List<char> {'a','e','i','o','u', 'A', 'E', 'I', 'O', 'U' }; return tmpVokaList.Aggregate(inText, (inCurrent, inVokal) => inCurrent.Replace(inVokal.ToString(),inVokal + "lew" + inVokal.ToString().ToLower())); } }

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string extension = "lew"; char[] vowels = new char[] { 'e', 'a', 'i', 'o', 'u' }; Console.WriteLine("Bitte geben Sie einen Text ein:"); string input = Console.ReadLine(); foreach (char vowel in vowels) { int i = 0; while ((i = input.ToLower().IndexOf(vowel, i)) != -1) { input = input.Insert(i + 1, extension + vowel ); i += extension.Length + 2; if (i>input.Length) { break; } } } Console.WriteLine(input); } }
Habs zwar noch nicht probiert aber sollte eigentlich klappen. So weit ich weiß wird auch nur ein lew pro wort dran gehängt. Sprich bei dem wort "aber" wäre es "alewaber" und nicht "alewabelewer".
C#-Code

class Program { static void main(string[] args) { Console.Write("Text: "); string text = Console.ReadLine(); Console.Write(BuildText(text)); } static bool IsVokal(char chr) { char[] vokale = 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'; foreach(char vokal in voakel) { if(chr == vokal) return true; } return false; } static string BuildText(string text) { StringBuilder sb = new StringBuilder(); for(int i = 0; i < text.Length; i++) { if(IsVokal(text[i])) sb.Append(text[i] + "lew" + text[i] + " "); } return sb.ToString(); } }

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace LoeffelspracheTYP { class Program { static void Main(string[] args) { string input; string output = ""; Regex regex = new Regex("[aeiou]"); Console.Write("Eingabe: "); input = Console.ReadLine(); foreach(char character in input) { if(regex.Match(character.ToString().ToLower()).Success) { output += character + "lew" + character; } else { output += character; } } Console.WriteLine("Umgewandelt: " + output); Console.ReadLine(); } } }