Skip to content

Instantly share code, notes, and snippets.

@syron
Created March 2, 2021 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syron/96768894bdc256fdd19bff0891fb1ea3 to your computer and use it in GitHub Desktop.
Save syron/96768894bdc256fdd19bff0891fb1ea3 to your computer and use it in GitHub Desktop.
/// <summary>
/// Inspired by D.S. :)
/// </summary>
/// <param name="stringInput"></param>
/// <param name="numberOfChars"></param>
/// <returns></returns>
public static string Versatilizaastoosanon_v2(this string stringInput, int numberOfChars)
{
// Check if numberofchars is 0 or below 0. If yes, return empty string.
if (numberOfChars <= 0)
return string.Empty;
// Check if numberofchars is higher than the number of digits in string. If yes, change it to length of string.
if (numberOfChars > stringInput.Length)
numberOfChars = stringInput.Length;
// Check if numberofchars is equal the number of digits in string. If yes, return string in uppercase.
if (numberOfChars == stringInput.Length)
return stringInput.ToUpper();
var chars = stringInput.ToArray();
string result = string.Empty;
for (int i = 0; i < numberOfChars; i++)
{
result += chars[i];
}
return result.ToUpper();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment