Created
March 2, 2021 20:43
-
-
Save syron/96768894bdc256fdd19bff0891fb1ea3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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