ASP.NET uses custom functions to switch between uppercase and lowercase strings

  • 2021-06-29 10:45:31
  • OfStack

This article describes an example of ASP.NET using custom functions to switch the case of strings.Share it for your reference.The implementation is as follows:

Method 1:


public string ToggleCase(string input)
{
  string result = string.Empty;
  char[] inputArray = input.ToCharArray();
  foreach (char c in inputArray)
  {
    if (char.IsLower(c))
      result += c.ToString().ToUpper();
    else if (char.IsUpper(c))
      result += c.ToString().ToLower();
    else
      result += c.ToString();
  }
  return result;
}

Method 2:


public string ToggleCase(string input)
{
  string result = string.Empty;
  char[] inputArray = input.ToCharArray();
  foreach (char c in inputArray)
  {
    if (char.IsLower(c))
      result += Char.ToUpper(c);
    else
      result += Char.ToLower(c);
  }
  return result;
}

I hope that the description in this paper will be helpful to everyone's ASP.NET program design.


Related articles: