How to Find out special char ‘_’ in a string and convert next char to lower if in upper and vise versa of this problem Input : shiv_Kumar Output : shivkumar

Add caption



How to Find out special char ‘_’ in a string and convert next char to lower if in upper and vise versa of this problem

Input :           shiv_Kumar
Output :        shivkumar

Input :           thisIsShivKumarTutorials
OutPut :        this_is_shiv_kumar_tutorials

Input :           this_Is_Shiv_Kumar_Tutorials
OutPut :        thisisshivkumartutorials


static void FindCharinString(string arr)

        {

           char[] chr = arr.ToCharArray();
            //Array.Sort(chr); //SORTING ARRAY
            string newstr = "";
            if (arr.Contains('_') == true)
            {
                for (int i = 0; i < chr.Length; i++)
                {
                    if (chr[i] == '_')
                    {
                        chr[i + 1] = Char.ToLower(chr[i + 1]);
                    }
                    else
                    {
                        newstr += chr[i].ToString();
                    }
                }
            }
            else
            {
                for (int i = 0; i < chr.Length; i++)
                {
                    if (chr[i] == char.ToUpper(chr[i]))
                    {
                        newstr += "_" + char.ToLower(chr[i]);
                    }
                    else
                    {
                        newstr += chr[i].ToString();
                    }
                }
            }

            Console.WriteLine(newstr); }

Share:

No comments:

Post a Comment

Popular

Tags

Mobile

Recent Posts