Reversing the given string without using reverse function [closed]

By using Regexes 🙂

var str = "Welcome to the world";

var parts = System.Text.RegularExpressions.Regex.Split(str, " ");
Array.Reverse(parts);

var sb = new StringBuilder();

foreach (var part in parts)
{
    sb.Append(part);
    sb.Append(' ');
}

if (sb.Length > 0)
{
    sb.Length--;
}

var str2 = sb.ToString();

Note that Regex(es) aren’t part of the System.String class 🙂 🙂 (they are System.Text.RegularExpressions.Regex)

Browse More Popular Posts

Leave a Comment