Reverse a string without using reverse()

Hi guys.

I want to reverse a string without using a reverse function. We can convert the string into CharArray but what should we do post that? Thanks for the help in advance.

Hi @heeru_ahuja,

Welcome to the UIpath Community

we can use While loop here :

  • First, the length of the input string is counted.

  • Based on the length, the While loop runs.

  • It starts assigning characters one by one from the last index of the character to a reversestring variable.

  • Decrement the length by one every time the loop runs.

    string reversestring = “”;
    int length;

    length = stringInput.Length - 1;

    while (length >= 0)
    {
    reversestring = reversestring + stringInput[length];
    length–;
    }
    Print(reversestring);

Source : Reverse A String In C# With And Without An Inbuilt Function


Mukesh

3 Likes

Hi @heeru_ahuja,

This topic might help..

2 Likes

Thanks

Thank you

Thank you @mukeshkala