Given the line "hello there, compiler.", How can I cancel every word except punctuation. Therefore, after this is completed, it will be printed: "olleh ereht, relipmoc". instead of "olleh, ereht.relipmoc"
My code (which ignores punctuation):
static string ReverseString(string s)
{
StringBuilder sb = new StringBuilder();
string[] words = s.Split(' ');
foreach (var word in words)
{
for (int i = word.Length - 1; i >= 0; i--)
{
sb.Append(word[i]);
}
sb.Append(" ");
}
return sb.ToString();
}
source
share