public static string ToNumberString(this long number, LetterCase letterCase = LetterCase.LowerCase) { var converter = new NumberToTextSpeller( TransformTextFactory.GetTransformation(letterCase)); return(converter.Spell(number)); }
public static string ToCheckAnnotation(this float number, LetterCase letterCase = LetterCase.LowerCase, bool includeWordDollars = true, bool includeWordCents = false) { var checkAnnotator = new CheckAnnotationSpeller( TransformTextFactory.GetTransformation(letterCase), includeWordDollars, includeWordCents); return(checkAnnotator.Spell(number)); }
public void Write_Byte(byte input, LetterCase letterCase, string expected) { var chars = new char[2]; Hexadecimal.Write(input, chars, letterCase); Assert.Equal(expected, new string(chars)); }
public static string ToNumberString(this double number, LetterCase letterCase = LetterCase.LowerCase) { var speller = new FloatingPointSpeller( TransformTextFactory.GetTransformation(letterCase)); return(speller.Spell(number)); }
public void Write_UInt64(ulong input, LetterCase letterCase, string expected) { var chars = new char[16]; Hexadecimal.Write(input, chars, letterCase); Assert.Equal(expected, new string(chars)); }
public RichTekst(string text, string letterseparator, LetterCase letterCase, bool underline, bool reverseOrder, ConsoleColor consoleColor) { Tekst = text; LetterSeparator = letterseparator; LetterCase = letterCase; Underline = underline; ReverseOrder = reverseOrder; ConsoleColor = consoleColor; }
public void Write(byte[] input, LetterCase @case, char?separator, string expected) { var chars = new char[expected.Length]; Hexadecimal.Write(input, chars, separator, @case); var actual = new string(chars); Assert.Equal(expected, actual); }
public static Span <char> Write(byte value, Span <char> output, LetterCase letterCase = LetterCase.Upper) { ValidateSufficientlySizedBuffer(output.Length, sizeof(byte), nameof(output)); var digits = letterCase == LetterCase.Lower ? LowerCaseDigits : UpperCaseDigits; output[0] = digits[value >> 4]; output[1] = digits[value & 0x0f]; return(output[2..]);
/// <summary> /// Преобразует перечисление в строку, где строковые значения всех записей соединяются, а между ними устанавливается заданный разделитель. Для перечисления должен быть задан атрибут <see cref="System.FlagsAttribute"/>. /// </summary> /// <param name="enum">Преобразумое перечисление.</param> /// <param name="separator">Разделитель между строковыми значениями перечисления.</param> /// <param name="letterCase">Регистр букв, применяемый к строковым значениям перечисления.</param> /// <returns>Строковое представление перечисления.</returns> /// <exception cref="System.ArgumentNullException">Значение параметра <paramref name="enum"/> равно <see langword="null"/>.</exception> /// <exception cref="System.ArgumentNullException">Значение параметра <paramref name="separator"/> равно <see langword="null"/>.</exception> /// <exception cref="System.ArgumentException">Значение параметра <paramref name="separator"/> является пустой строкой.</exception> public static string ToString(this Enum @enum, string separator, LetterCase letterCase) { #region Проверка параметров if (@enum == null) { throw new ArgumentNullException("enum"); } if (separator == null) { throw new ArgumentNullException("separator"); } if (separator.Length == 0) { throw ExceptionHelper.EmptyString("separator"); } #endregion var strBuilder = new StringBuilder(); Array values = Enum.GetValues(@enum.GetType()); foreach (Enum value in values) { if (@enum.HasFlag(value)) { string valueInStr = value.ToString(); switch (letterCase) { case LetterCase.Upper: valueInStr = valueInStr.ToUpper(); break; case LetterCase.Lower: valueInStr = valueInStr.ToLower(); break; } strBuilder.Append(valueInStr); strBuilder.Append(separator); } } if (strBuilder.Length != 0) { strBuilder.Remove(strBuilder.Length - separator.Length, separator.Length); } return strBuilder.ToString(); }
/// <summary> /// 32位MD5加密 /// </summary> /// <param name="password"></param> /// <returns></returns> public static string MD5Encrypt32(string password, LetterCase letterCase = LetterCase.UpperCase) { string cl = password; string pwd = ""; MD5 md5 = MD5.Create(); //实例化一个md5对像 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 for (int i = 0; i < s.Length; i++) { // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 pwd = pwd + s[i].ToString(letterCase == LetterCase.UpperCase ? "X2" : ""); } return(pwd); }
public static ITransformText GetTransformation(LetterCase letterCase) { switch (letterCase) { case LetterCase.UpperCase: return(new UpperCaseTransformation()); case LetterCase.LowerCase: return(new LowerCaseTransformation()); case LetterCase.TitleCase: return(new TitleTextTransformation()); default: throw new NotImplementedException(letterCase + " is not supported."); } }
private static char GetRandomCharacter(Random random, LetterCase casing = LetterCase.Uppercase) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var generatedChar = chars[random.Next(chars.Length)]; switch (casing) { case LetterCase.LowerCase: return(char.ToLower(generatedChar)); case LetterCase.Mixed: return(random.NextBoolean() ? char.ToLower(generatedChar) : generatedChar); default: return(generatedChar); // was upper case in the chars list } }
public void FormateSpelling(LetterCase letterCase) { switch (letterCase) { case LetterCase.Upper: spelling = spelling.ToUpper(); break; case LetterCase.Lower: spelling = spelling.ToLower(); break; case LetterCase.Capital: spelling = spelling[0].ToString().ToUpper() + spelling.Substring(1).ToLower(); break; } }
private static void GetSymbol(ref string ch) { LetterCase letterCase = NextGenericEnum <LetterCase>(); switch (letterCase) { case LetterCase.Lower: ch = ch.ToLower(); break; case LetterCase.Top: ch = ch.ToUpper(); break; case LetterCase.Alternative: ch = GetAlternativeSymbol(ch); break; } }
/// <summary> /// Generates a random string, using the provided format /// </summary> /// <param name="random">existing random</param> /// <param name="format">The method will replace every 0 with a random number and every # with a random character</param> /// <param name="casing">Specifies the letter case of the generated characters</param> /// <returns>A randomly generated string, using the format</returns> public static string GetString(this Random random, string format, LetterCase casing = LetterCase.Uppercase) { // Based on http://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-centerValue // Added logic to specify the format of the random string (# will be random string, 0 will be random numeric, other characters remain) var result = new StringBuilder(); for (var formatIndex = 0; formatIndex < format.Length; formatIndex++) { switch (format.ToUpper()[formatIndex]) { case '0': result.Append(GetRandomNumeric(random)); break; case '#': result.Append(GetRandomCharacter(random, casing)); break; default: result.Append(format[formatIndex]); break; } } return(result.ToString()); }
/// <summary> /// Convert string to Lower or Upper case /// </summary> /// <param name="caseType">The type of letter case</param> /// <returns></returns> public async Task ChangeLetterCaseAsync(LetterCase caseType) { if (string.IsNullOrEmpty(InputTextArea)) { return; } switch (caseType) { case LetterCase.Upper: OutputTextArea = await Task.Run(() => _tempText.ToUpper()); break; case LetterCase.Lower: OutputTextArea = await Task.Run(() => _tempText.ToLower()); break; } AffectedCharacter = _tempText.Length - Regex.Matches(_tempText, @"\s|\d").Count; UpdatePersistency(); }
public int StrEndLetterCount(LetterCase Case = LetterCase.Both) { var Ret = 0; for (var i = Index + Length - 1; i >= Index; i--) { var C = String[i]; if (Char.IsLetter(C)) { if ((Char.IsUpper(C) && Case != LetterCase.OnlyLower) || (Char.IsLower(C) && Case != LetterCase.OnlyUpper)) { Ret++; continue; } } break; } return(Ret); }
public bool ToNumber(int Radix, LetterCase Case, out BigInteger Ret) { Ret = 0; if (Length == 0) { return(false); } for (var i = Index; i < Index + Length; i++) { var Chr = String[i]; var Num = -1; if (Chr >= '0' && Chr <= '9') { Num = Chr - '0'; } else if (Chr >= 'a' && Chr <= 'z' && Case != LetterCase.OnlyUpper) { Num = Chr - 'a' + 10; } else if (Chr >= 'A' && Chr <= 'Z' && Case != LetterCase.OnlyLower) { Num = Chr - 'A' + 10; } if (Num == -1 || Num >= Radix) { return(false); } else { Ret = Ret * Radix + Num; } } return(true); }
public static string ConvertLetterCaseTo(this string str, string langCode, LetterCase letterCase) { var cultureInfo = CultureInfo.GetCultureInfo(langCode); switch (letterCase) { case LetterCase.Lowercase: return(str.ToLower(cultureInfo)); case LetterCase.Uppercase: return(str.ToUpper(cultureInfo)); case LetterCase.TitleCase: return(cultureInfo.TextInfo.ToTitleCase(str)); case LetterCase.SentenceCase: var r = new Regex(@"(^[a-z])|\.\s+(.)", RegexOptions.ExplicitCapture); var result = r.Replace(str.ToLower(), s => s.Value.ToUpper()); return(result); default: throw new NotImplementedException(); } }
/// <summary> /// 是否为指定规则的字母 /// </summary> /// <param name="input"></param> /// <param name="letterCase">指定大小写规则</param> /// <returns></returns> public static bool IsLetter(string input, LetterCase letterCase) { char[] cs = input.ToCharArray(); if (letterCase == LetterCase.SupperAndLower) { foreach (char c in cs) { //lower if (c > 96) { if (c < 123) { } else { return(false); } } //upper else if (c > 64) { if (c < 91) { } else { return(false); } } else { return(false); } } } else if (letterCase == LetterCase.Supper) { foreach (char c in cs) { //upper if (c > 64 && c < 91) { } else { return(false); } } } else if (letterCase == LetterCase.Lower) { foreach (char c in cs) { //lower if (c > 96 && c < 123) { } else { return(false); } } } return(true); }
public void ChangeCase(LetterCase value) { throw new NotImplementedException(); }
protected override string ToHex(StationEui eui, char?separator, LetterCase letterCase) => eui.ToHex(separator, letterCase);
protected override string ToHex(StationEui eui, LetterCase letterCase) => eui.ToHex(letterCase);
public CodeString EndStr(LetterCase Case = LetterCase.Both) { var C = StrEndLetterCount(Case); return(C == 0 ? Substring(Length) : Substring(String.Length - C)); }
public CodeString CutEndStr(LetterCase Case = LetterCase.Both) { var C = StrEndLetterCount(Case); return(C == 0 ? this : Substring(0, String.Length - C)); }
public int StrEndLetterCount(LetterCase Case = LetterCase.Both) { return(String.StrEndLetterCount(Case)); }
public bool ToNumber(int Radix, LetterCase Case, out BigInteger Ret) { return(String.ToNumber(Radix, Case, out Ret)); }
public ENotationSkipper(LetterCase HEXLetterCase = LetterCase.OnlyUpper) { this.HEXLetterCase = HEXLetterCase; }
/// <summary> /// Converts string keys in <see cref="PhpArray"/> to specified case. /// </summary> /// <param name="array">The <see cref="PhpArray"/> to be converted.</param> /// <param name="keyCase">The <see cref="LetterCase"/> to convert keys to.</param> /// <returns>The copy of <paramref name="array"/> with all string keys lower cased.</returns> /// <remarks>Integer keys as well as all values remain unchanged.</remarks> //[return: PhpDeepCopy] public static PhpArray array_change_key_case(PhpArray array, LetterCase keyCase) { PhpArray result; switch (keyCase) { case LetterCase.Lower: result = StringKeysToLower(array); break; case LetterCase.Upper: result = StringKeysToUpper(array); break; default: //PhpException.InvalidArgument("keyCase"); //goto case LetterCase.Upper; throw new ArgumentException(nameof(keyCase)); } //result.InplaceCopyOnReturn = true; return result; }
public static PhpArray ChangeKeyCase(PhpArray array, LetterCase keyCase) { PhpArray result; switch (keyCase) { case LetterCase.Lower: result = StringKeysToLower(array); break; case LetterCase.Upper: result = StringKeysToUpper(array); break; default: PhpException.InvalidArgument("keyCase"); goto case LetterCase.Upper; } result.InplaceCopyOnReturn = true; return result; }
/// <summary> /// ValidateLetter(): /// Validate a letter input. Prevent user from entering empty input, numbers or a blank space /// /// Arguments: /// -A selection mode that determines whether the input is converted to an upper or lower case or left alone before returning /// /// Steps: /// #1 Validating Input /// -Try get user input /// -Check if input is a letter /// -Check if input is more than 1 character /// -Check if input is empty /// -Check if input contains white space /// -If input passes all checks then move to Step 2, /// -Otherwise print to console error, prompt user to make another input /// #2 Returning Input /// -Evaluate the argument passed /// -If upper casing, then return the input as upper case character /// -If lower casing, then return the input as lower case character /// -If default, then return the input as it was /// </summary> public static char ValidateLetter(LetterCase letterCasing = LetterCase.Default) { string userInput; for (; ;) { userInput = Console.ReadLine(); //Accept letters only if (userInput.All(char.IsLetter)) { //Cause user to input again if more than 1 char if (userInput.Length > 1) { Console.WriteLine("Too many characters!\nPlease enter a letter from A to Z"); } //Cause user to input again if they didn't enter anything else if (userInput.Length == 0) { Console.WriteLine("You didn't enter anything!\nPlease enter a letter from A to Z"); } //Cause user to input again if they entered blank spaces else if (userInput[0] == ' ') { Console.WriteLine("You didn't enter anything!\nPlease enter a letter from A to Z"); } //Successful input else { switch (letterCasing) { case LetterCase.Upper: //Check if input is already uppercase before returning if (!userInput.All(char.IsUpper)) { return(userInput.ToUpper()[0]); } return(userInput[0]); case LetterCase.Lower: //Check if input is already lowercase before returning if (!userInput.All(char.IsLower)) { return(userInput.ToLower()[0]); } return(userInput[0]); case LetterCase.Default: return(userInput[0]); default: return(userInput[0]); } } } //Catch numeric and non alphabetical input. else { Console.WriteLine("Letters only!\nPlease enter a letter from A to Z"); } } }