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 : https://www.c-sharpcorner.com/blogs/reverse-string-without-inbuilt-function-and-using-inbuilt-function


Mukesh

2 Likes

Hi @heeru_ahuja,

This topic might help..

2 Likes

Thanks

Thank you