Feedback

Letztes Wort aus einem String ermitteln

Sprache: C#

Gibt das letzte Wort aus einem String zurück.
// using System.Text.RegularExpressions;

/// <summary>
/// Gets the last word of the given string.
/// </summary>
/// <param name="token">The token.</param>
/// <returns>the last word of the given string</returns>
private static string GetLastWordOfString(string token)
{
    string[] words = Regex.Split(token.TrimEnd(), @"[s]");
    return words[words.Length-1];
}
// using System.Text.RegularExpressions;

/// <summary>
/// Gets the last word of the given string.
/// </summary>
/// <param name="token">The token.</param>
/// <returns>the last word of the given string</returns>
private static string GetLastWordOfString(string token)
{
    string[] words = Regex.Split(token.TrimEnd(), @"[s]");
    return words[words.Length-1];
}