String Reversal This will print the string in reverse order.
public string StringReversal(string stringToBeReversed)
{
string retStr = "";
Stack chars = new Stack();
foreach (char c in stringToBeReversed)
{
chars.Push(c);
}
while (chars.Count > 0)
{
Console.Write(chars.Pop());
}
Console.Read();
return retStr = chars.ToString();
}
Tokenizer This will print each word in phrase on separate line with punctuation removed
using a Regular Expression.
public List<string> tokenizer (String phrase)
{
List<string> retList = new List<string>();
phrase = Regex.Replace(phrase, @"[^\w\s]" , string.Empty);
string[] tokens = phrase.Split(' ');
foreach (string token in tokens)
{
retList.Add(token);
Console.WriteLine(token);
}
Console.Read();
Console.WriteLine(); // insert blank line
return retList;
}