Git Product home page Git Product logo

uebung-041's Introduction

Uebung-041 -- String Separation

📎Angabe .pdf

📊 Lernziele:

  • ↳ Stringbearbeitung

🧮 Aufgabenstellung:

  • Schreiben Sie ein Programm, welches vom Benutzer einen beliebigen Text und ein weiteres Zeichen „Split“ einliest.
  • Anschließend splitten Sie den eingegebenen Text, nach jedem Vorkommen des Zeichens „Split“ im Text auf.

🔎 Ausgabe Bsp.

Benutzerschnittstelle :
Ausgabebeispiel 📎

🧩 Hinweis / Ablauf 🧠💭

Ablauf:

) Die Benutzereingaben dürfen im gesamten Programm nicht verändert werden und müssen erhalten bleiben.

) Zur Lösung dieser Aufgabe dürfen Sie nicht die Standard-Methoden von String verwenden!


SPOILER Lösung :

🖥 Ausgabe:

meine Ausgabe:
Ausgabe 📎

💾 C# - Programm:

👉 ausklappen 👈
namespace StringSeparation  //  
{                           //
 public class Program      //
 {                         //
   static void Main()      //
   {
     ///*----------------------- console_settings ------------------------*///
     const int cWidth = 53;                     //  console width
     const int cHeight = 30;                    //  & height
     Console.SetWindowSize(cWidth, cHeight);    //
     Console.OutputEncoding = Encoding.UTF8;    //  Unicode Symbols

     /*----------------------------- VARIABLES -----------------------------*/
     string userInput, textCache,                     //
            splitCache = "";                          //
     char splitChar;                                  //  
     int index;                                       //
     bool abortInput = false,                         //  abort condition for input
          abortSplit = true;                          //  abort condition if SplitChar is not found in Text

     /*-------------------------------- HEAD -------------------------------*/
     Console.Clear();
     Console.Write("\n                 String Separation                   " +
     /* cWidth: */ "\n=====================================================");

     /*---[IN:]-------------------- PROMPT_USER ----------------------------*/
     Console.Write("\n Geben Sie den Text ein, den Sie aufsplitten wollen:" +
                   "\n");
     do    //----------------------- GET_INPUT_STRING ----------------------//
     {                                                                      //
       userInput = Console.ReadLine();                                      //  text to split + [enter]
       textCache = userInput;                                               //  safe input to cache     
       abortInput = (textCache.Length > 1) ? false : true;                  //
       if (abortInput)                                                      //
       {                                                                    //
         Console.Write($"\n Ihre Eingabe: '{textCache}' ist unteilbar." +   //
                       $"\n Wiederholen Sie die Eingabe:" +                 //
                       $"\n");                                          //
       }                                                                    //
     } while (abortInput);                                                  //  repeat INPUT if abortInput = true

     //--------------------------- GET_INPUT_CHAR --------------------------//
     Console.Write("\n Wählen Sie das Zeichen an dem gesplittet werden soll:" +
                   "\n");                                               //
     splitChar = Console.ReadKey().KeyChar;                                 //  char ✂ to ✂ split


     //===[CALC:]===========================================================//  test if SplitChar is present in Text
     index = 0;                                                             //
     while ((index + 1) < textCache.Length && (abortSplit == true))         //
     {                                                                      //
       abortSplit = (textCache[index] == splitChar) ? false : true;         //
       index++;                                                             //
     }                                                                      //
     Console.Write($"\n Das Split-Zeichen '{splitChar}' wurde {(abortSplit ? "nicht gefunden" : "gefunden")} " +
                    "\n -----------------------------------------------------" +
                    "\n ");                                                 //
     if (abortSplit == false)                                               //
     {                                                                      //
       // Console.Write("weiter");                                          //
       index = 0;                                                           //
       while ((index + 1) <= textCache.Length)                              //
       {                                                                    //
         if (splitChar != textCache[index])                                 //
         {                                                                  //
           splitCache = splitCache + textCache[index];                      //
           index++;                                                         //
         }                                                                  //
         else                                                               //
         {                                                                  //
           Console.Write($"\n {splitCache} ");                              //
           splitCache = "";                                                 //
           index++;                                                         //
         }                                                                  //
       }                                                                    //
       Console.Write($"\n {splitCache} ");                                  //
     }                                                                      //
     /*-------------------------------- END --------------------------------*/
     Console.Write("\n=====================================================" +
                   "\n Zum beenden Eingabetaste drücken..");
     Console.ReadLine();    //  wait for [enter]
     Console.Clear();       //
   }
 }
}

[..weiterführende Quelle..]

-->

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.