private string AddLogin(string name, string surname) { string result = (surname + name.First()).ToLower(); do { string Login = result; if (Check_If_Login_Is_Database(result) == true) { char lastItem = Login.Last(); if (Char.IsNumber(lastItem) == true) { string Without_Last_Item = Login.Trim(lastItem); int addNumber = (CharUnicodeInfo.GetDecimalDigitValue(lastItem) + 1); Login = string.Concat(Without_Last_Item, addNumber); result = Login; } else { result = Login + "1"; } } else { result = Login; } } while (Check_If_Login_Is_Database(result) == true); return(result); }
protected override bool OnValidate(string identification) { if (identification.Length != StandardMaxLength) { return(false); } if (identification == new string('0', StandardMaxLength)) { return(false); } long checkSum = 0L; for (int i = 0; i < StandardMaxLength; i++) { int n = 9 - i; int product = CharUnicodeInfo.GetDecimalDigitValue(identification[i]) * n; if (n == 1) { product = -product; } checkSum += product; } long modulo11 = checkSum % 11; return(modulo11 == 0); }
/// <summary> /// Writes integers in different sizes based on /// digit characters in the <paramref name="format"/> string. /// <para> /// Zero skips a value, while other characters are ignored. /// Maximum size of one integer is 8 bytes. /// </para> /// </summary> public static void WriteFormat( this ImageBinWriter s, ReadOnlySpan <char> format, ReadOnlySpan <long> values) { if (s == null) { throw new ArgumentNullException(nameof(s)); } Span <byte> buffer = stackalloc byte[sizeof(long)]; int valueIndex = 0; for (int i = 0; i < format.Length; i++) { int digit = CharUnicodeInfo.GetDecimalDigitValue(format[i]); if (digit == -1 || digit > buffer.Length) { continue; } if (digit > 0) { long x = values[valueIndex]; for (int j = 0; j < digit; j++) { int shift = 8 * j; buffer[j] = (byte)((x >> shift) & 0xff); } s.Write(buffer.Slice(0, digit)); } valueIndex++; } }
private static int ConvertToIntInternal(this string stringToConvert) { //break if we're at the end. if (stringToConvert.Length == 1) { return(CharUnicodeInfo.GetDecimalDigitValue(stringToConvert[0])); } var currentDigitChar = stringToConvert[stringToConvert.Length - 1]; var currentDigit = CharUnicodeInfo.GetDecimalDigitValue(currentDigitChar); if (currentDigit == -1) { return(-1 * ConvertToIntInternal(stringToConvert.Remove(stringToConvert.Length - 1))); } var resultToLeftOfCurrentDigit = ConvertToIntInternal(stringToConvert.Remove(stringToConvert.Length - 1)); //We hit a decimal. if (resultToLeftOfCurrentDigit < 0) { return(resultToLeftOfCurrentDigit); } var total = currentDigit + 10 * ConvertToIntInternal(stringToConvert.Remove(stringToConvert.Length - 1)); return(total); }
public static void NegativeDigitsTest() { for (int i = 0; i < s_nonNumericsCodepoints.Length; i++) { Assert.Equal(-1, CharUnicodeInfo.GetDecimalDigitValue(s_nonNumericsCodepoints[i])); Assert.Equal(-1, CharUnicodeInfo.GetDecimalDigitValue(s_nonNumericsCodepoints, i)); } }
public static void PrintProperties(char c) { Console.Write(" {0,-3}", c); Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(c)); Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(c)); Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(c)); Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(c)); }
/// <summary> /// The get decimal digit value. /// </summary> /// <param name="ch"> /// The ch. /// </param> /// <returns> /// The <see cref="byte"/>. /// </returns> /// <exception cref="ArgumentOutOfRangeException"> /// </exception> public static byte GetDecimalDigitValue(char ch) { var decimalDigitValue = CharUnicodeInfo.GetDecimalDigitValue(ch); if ((decimalDigitValue < 0) || (decimalDigitValue > 9)) { throw new ArgumentOutOfRangeException("ch"); } return((byte)decimalDigitValue); }
public static int GetDecimal(string binary) { var result = 0; for (int i = binary.Length - 1; i > -1; i--) { result += CharUnicodeInfo.GetDecimalDigitValue(binary[i]) << i; } return(result); }
public void GetDecimalDigitValue_Char() { for (int i = 0; i <= char.MaxValue; i++) { char ch = (char)i; CodePoint knownGoodData = UnicodeData.GetData(ch); int actualValue = CharUnicodeInfo.GetDecimalDigitValue(ch); AssertEqual(knownGoodData.DecimalDigitValue, actualValue, nameof(CharUnicodeInfo.GetDecimalDigitValue), knownGoodData); } }
public static void DigitsDecimalTest() { Assert.Equal(s_numericsCodepoints.Length % 10, 0); for (int i = 0; i < s_numericsCodepoints.Length; i += 10) { for (int j = 0; j < 10; j++) { Assert.Equal(j, CharUnicodeInfo.GetDecimalDigitValue(s_numericsCodepoints[i + j])); Assert.Equal(j, CharUnicodeInfo.GetDecimalDigitValue(s_numericsCodepoints, i + j)); } } }
public int LastStoneWeight(int[] stones) { var list = stones.ToList <int>(); list = list.OrderBy(x => x).ToList(); while (list.Count >= 2) { int n = list.Count; var max1 = list[n - 1]; var max2 = list[n - 2]; var diff = max1 - max2; list.RemoveAt(list.Count - 1); list.RemoveAt(list.Count - 1); var idx = list.BinarySearch(diff); if (idx > 0) { list.Insert(idx + 1, diff); } else { string s = "100"; int x = (int)char.GetNumericValue(s[0]); CharUnicodeInfo.GetDecimalDigitValue('1'); if (list.Count == 1) { if (list[0] <= diff) { list.Add(diff); } else { list.Insert(0, diff); } } else { if (-idx >= list.Count) { list.Add(diff); } else { list.Insert(-idx, diff); } } } } return(list[0]); }
//Fill the matrix from the string private static void FillMatrix() { int z = 0; for (int i = 0; i < MatrixD.Width; i++) { for (int j = 0; j < MatrixD.Height; j++) { MatrixD.MatrixZero[i, j] = CharUnicodeInfo.GetDecimalDigitValue(MatrixD.InputString[z]); z++; } } }
public static void Main() { // The String to get information for. String s = "a9\u0393\u00B2\u00BC\u0BEF\u0BF0\u2788"; Console.WriteLine("String: {0}", s); // Print the values for each of the characters in the string. Console.WriteLine("index c Num Dig Dec UnicodeCategory"); for (int i = 0; i < s.Length; i++) { Console.Write("{0,-5} {1,-3}", i, s[i]); Console.Write(" {0,-5}", CharUnicodeInfo.GetNumericValue(s, i)); Console.Write(" {0,-5}", CharUnicodeInfo.GetDigitValue(s, i)); Console.Write(" {0,-5}", CharUnicodeInfo.GetDecimalDigitValue(s, i)); Console.WriteLine("{0}", CharUnicodeInfo.GetUnicodeCategory(s, i)); } }
private static void VerifyNativeDigits(string[] nativeDig, string propertyName) { if (nativeDig == null) { throw new ArgumentNullException(propertyName, SR.ArgumentNull_Array); } if (nativeDig.Length != 10) { throw new ArgumentException(SR.Argument_InvalidNativeDigitCount, propertyName); } for (int i = 0; i < nativeDig.Length; i++) { if (nativeDig[i] == null) { throw new ArgumentNullException(propertyName, SR.ArgumentNull_ArrayValue); } if (nativeDig[i].Length != 1) { if (nativeDig[i].Length != 2) { // Not 1 or 2 UTF-16 code points throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName); } else if (!char.IsSurrogatePair(nativeDig[i][0], nativeDig[i][1])) { // 2 UTF-6 code points, but not a surrogate pair throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName); } } if (CharUnicodeInfo.GetDecimalDigitValue(nativeDig[i], 0) != i && CharUnicodeInfo.GetUnicodeCategory(nativeDig[i], 0) != UnicodeCategory.PrivateUse) { // Not the appropriate digit according to the Unicode data properties // (Digit 0 must be a 0, etc.). throw new ArgumentException(SR.Argument_InvalidNativeDigitValue, propertyName); } } }
public void navClick(object sender, EventArgs e) { LinkButton btnLink = (LinkButton)sender; int clickedItem = CharUnicodeInfo.GetDecimalDigitValue(btnLink.ID[btnLink.ID.Length - 1]); switch (clickedItem) { case 1: //new customer Response.Redirect("home.aspx"); break; case 2: // reservations if ((UserType)(Session["UserType"]) == UserType.Owner) { Response.Redirect("managePet.aspx"); } else { Response.Redirect("owners.aspx"); // this will be changed when Owners.aspx is added } break; case 3: //Handle Clerk edit profile if ((UserType)(Session["UserType"]) == UserType.Owner) { Response.Redirect("manageCustomer.aspx"); } else { Session["SelectedOwner"] = null; Response.Redirect("manageCustomer.aspx"); } break; } }
public string DigitKeysToCharValues(string digitKeySeriesToDecode) { string output = ""; for (int index = 0; index < digitKeySeriesToDecode.Length; index++) { char rowDigit = digitKeySeriesToDecode[index]; if (Array.Exists(_threeRowDigitKeys.ToCharArray(), rowKey => rowKey.Equals(rowDigit))) { // Is not an ESTLAND coordinate. index++; int columnDigit = CharUnicodeInfo.GetDecimalDigitValue(digitKeySeriesToDecode[index]); output += _keyMatrix.FirstOrDefault(x => x.Key == $"{rowDigit}{columnDigit}").Value; } else { // Is a ESTLAND coordinate. output += _keyMatrix.FirstOrDefault( x => x.Key == rowDigit.ToString()).Value; } } return(output); }
public static bool TryParse( string template, [MaybeNullWhen(false)] out Template parsed, [MaybeNullWhen(true)] out string error) { if (template == null) { throw new ArgumentNullException(nameof(template)); } parsed = null; var elements = new List <Template>(); var i = 0; while (i < template.Length) { var ch = template[i]; if (ch == '{') { i++; if (i == template.Length) { error = "Character `{` must be escaped by doubling in literal text."; return(false); } if (template[i] == '{') { elements.Add(new LiteralText("{")); i++; } else { // No line/column tracking var tokens = Tokenizer.GreedyTokenize(new TextSpan(template, new Position(i, 0, 0), template.Length - i)); var expr = ExpressionTokenParsers.TryPartialParse(tokens); if (!expr.HasValue) { // Error message accuracy is not great here error = $"Invalid expression, {expr.FormatErrorMessageFragment()}."; return(false); } if (expr.Remainder.Position == tokens.Count()) { i = tokens.Last().Position.Absolute + tokens.Last().Span.Length; } else { i = tokens.ElementAt(expr.Remainder.Position).Position.Absolute; } if (i == template.Length) { error = "Un-closed hole, `}` expected."; return(false); } Alignment?alignment = null; if (template[i] == ',') { i++; if (i >= template.Length || template[i] == '}') { error = "Incomplete alignment specifier, expected width."; return(false); } AlignmentDirection direction; if (template[i] == '-') { direction = AlignmentDirection.Left; i++; if (i >= template.Length || template[i] == '}') { error = "Incomplete alignment specifier, expected digits."; return(false); } } else { direction = AlignmentDirection.Right; } if (!char.IsDigit(template[i])) { error = "Invalid alignment specifier, expected digits."; return(false); } var width = 0; while (i < template.Length && char.IsDigit(template[i])) { width = 10 * width + CharUnicodeInfo.GetDecimalDigitValue(template[i]); i++; } alignment = new Alignment(direction, width); } string?format = null; if (template[i] == ':') { i++; var formatBuilder = new StringBuilder(); while (i < template.Length && template[i] != '}') { formatBuilder.Append(template[i]); i++; } format = formatBuilder.ToString(); } if (i == template.Length) { error = "Un-closed hole, `}` expected."; return(false); } if (template[i] != '}') { error = $"Invalid expression, unexpected `{template[i]}`."; return(false); } i++; elements.Add(new FormattedExpression(expr.Value, format, alignment)); } } else if (ch == '}') { i++; if (i == template.Length || template[i] != '}') { error = "Character `}` must be escaped by doubling in literal text."; return(false); } elements.Add(new LiteralText("}")); i++; } else { var literal = new StringBuilder(); do { literal.Append(template[i]); i++; } while (i < template.Length && template[i] != '{' && template[i] != '}'); elements.Add(new LiteralText(literal.ToString())); } } if (elements.Count == 1) { parsed = elements.Single(); } else { parsed = new TemplateBlock(elements.ToArray()); } error = null; return(true); }
public int GetDecimalDigitValue() { return(CharUnicodeInfo.GetDecimalDigitValue((char)Value)); }