Beispiel:
string a=getAllAfterWord("Hello World",1); <-- a = "World"
Alles in C# muss in einem Namespace verfügbar sein. Ich werde als Namespace BGE benutzen was kurz ist für: ben0bis Game Engine. (Erklärung Namespaces)Da die Funktion global verfügbar ist, kommt sie in die Helpers-Klasse. Die Helpers-Klasse beeinhalted nur global verfügbare statische Helper Funktionen. (Erklärung static)
namespace BGE
{
  static public string getAllAfterWord(string source, int wichWord)
  {
    string target = "";
    int actualWord = 1;
    bool wordbegun = true;
    for (int i = 0; i < source.Length; i++)
    {
      if (source[i].ToString() == " " || source[i].ToString() == ",")
      {
        wordbegun = false;
      }else{
        if (!wordbegun)
        {
          wordbegun = true;
          actualWord++;
        }
      }
      if (actualWord > wichWord)
        target += source[i].ToString();
    }
    return target;
  }
}
 
 
Keine Kommentare:
Kommentar veröffentlichen