We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Thursday, July 9, 2015

Character reverse in string by word Without predefined function in C#

class Program
    {
        static int k;
        static string[] SToArray(string str)
        {
            int size = 1;
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == ' ')
                    size++;
            }
            string str1 = "";
            string[] sa = new string[size];
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == ' ')
                {
                    sa[k] = str1;
                    str1 = "";
                    k++;
                }
                else
                    str1 += str[i];
                if (i == str.Length - 1)
                    sa[k] = str1;
            }

            return sa;

        }

        static void Main()
        {
            Console.WriteLine("Enter the string: ");
            string input = Console.ReadLine();
            string[] revers = SToArray(input);
            foreach (string item in revers)
            {
                for (int i = item.Length - 1; i >= 0; i--)
                {
                    Console.Write(item[i]);
                }
                Console.Write(" ");
            }
            Console.ReadLine();
        }
            }




Output:

No comments: