Function to change string case in C#

public string ToggleCharacterCase(string PInput)
{
    string strResult = string.Empty;
    char[] arrInput = PInput.ToCharArray();
    foreach (char objChar in arrInput)
    {
        if (char.IsLower(objChar))
            strResult += objChar.ToString().ToUpper();
        else if (char.IsUpper(objChar))
            strResult += objChar.ToString().ToLower();
        else
            strResult += objChar.ToString();
    }
    return strResult;
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.