ganzewoort
6
Q:

reverse string c#

public static string ReverseString(string s)
    {
        char[] arr = s.ToCharArray();
        Array.Reverse(arr);
        return new string(arr);
    }
6
public static void Main(string[] args)
        {
            string s = "aeiouXYZ";
           Console.Write(Reverse(s) );
        }

        public static string Reverse(string s)
        {
            var result = new string(s.ToCharArray().Reverse().ToArray() );
            return result;
        }
------------------------------------------------------Option 2
foreach (int v in values.Select(x => x).Reverse())
{
      Console.Write(v + " ");
}
1
string str = "Hello World!"; // the string which you want to reverse
string reverse = "";
int length = str.Length - 1; 

while(length >= 0)
{
	reverse += str[length];
   	length--;
}

Console.WriteLine(reverse);  // output: "!dlroW olleH"
0
//Reverse string and reverse case
using System.Linq;
public class Hello{
    public static void Main(){
        string inputstring="AbcdeFhiJKl";
        char[] arr = new char[inputstring.Length];
        int i=0;
        foreach (char v in inputstring.Select(x => x).Reverse())
        {
            if (char.IsUpper(v)) { arr[i]=char.ToLower(v); }else{ arr[i]=char.ToUpper(v);};
            i=i+1;
        }
        string str = new string(arr);
        System.Console.WriteLine(str);
        System.Console.ReadLine();
    }
}
0

---------------------------------------------------Option 1
foreach (int v in values.Select(x => x).Reverse())
{
      Console.Write(v + " ");
}
---------------------------------------------------Option 2
       public static void Main(string[] args)
        {
            Console.Write( Reverse("ABcdefgH") );
        }

		public static string Reverse(string s)
        {
            string result = String.Empty;
            char[] cArr = s.ToCharArray();
            int end = cArr.Length - 1;

            for (int i = end; i >= 0; i--)
            {
                result += cArr[i];
            }
            return result;
        }
0
public void ReverseString(char[] s) {
        
        for(int i = 0; i < s.Length / 2; i++) {
    	    
            char temp = s[i];
    	    s[i] = s[s.Length - 1 - i];
    	    s[s.Length - 1 - i] = temp;
     
     }
}
-1

New to Communities?

Join the community