-
-
Notifications
You must be signed in to change notification settings - Fork 5
Detect
The Detect
class provides static methods and properties for detecting the decimal separator character in the current culture.
private static string Formula
Returns a string representation of a division formula, used to determine the separator character used in numerical values.
private static string Formula => $"{10 / 3f}";
-
Char
: Gets the decimal separator character in the current culture. -
CharCross
: Gets the opposite decimal separator character in the current culture. -
Enum
: Gets theSEDT
enumeration value that corresponds to theChar
field. -
EnumCross
: Gets theSEDT
enumeration value that corresponds to theCharCross
field. -
String
: Gets the string representation of theChar
field. -
StringCross
: Gets the string representation of theCharCross
field.
The SEDT
enumeration specifies the type of decimal separator character detected.
public enum DetectType
{
Dot,
None,
Comma
}
Char
Returns the separator character used in numerical values. If the separator character is a dot ('.'), returns '.'; otherwise, returns ','.
public static char Char => Formula.Contains('.') ? '.' : ',';
CharCross
Returns the opposite separator character of the one used in numerical values. If the separator character is a dot ('.'), returns ','; otherwise, returns '.'.
public static char CharCross => Char == '.' ? ',' : '.';
Enum
Returns the SEDT
value that corresponds to the separator character used in numerical values. If the separator character is a dot ('.'), returns SEDT.Dot
; if the separator character is a comma (','), returns SEDT.Comma
; otherwise, returns SEDT.None
.
public static SEDT Enum => Char switch
{
'.' => SEDT.Dot,
',' => SEDT.Comma,
_ => SEDT.None,
};
EnumCross
Returns the SEDT
value that corresponds to the opposite separator character of the one used in numerical values. If the separator character is a dot ('.'), returns SEDT.Comma
; if the separator character is a comma (','), returns SEDT.Dot
; otherwise, returns SEDT.None
.
public static SEDT EnumCross => CharCross switch
{
'.' => SEDT.Dot,
',' => SEDT.Comma,
_ => SEDT.None,
};
String
Returns a string representation of the separator character used in numerical values. If the separator character is a dot ('.'), returns "."; otherwise, returns ",".
public static string String => $"{Char}";
StringCross
Returns a string representation of the opposite separator character of the one used in numerical values. If the separator character is a dot ('.'), returns ","; otherwise, returns ".".
public static string StringCross => $"{CharCross}";
The following example demonstrates how to use the Detect
class to determine the decimal separator character and corresponding enumeration value in the current culture:
// Detect the decimal separator character
char decimalSeparator = Detect.Char;
Console.WriteLine($"Decimal separator: {decimalSeparator}");
// Detect the opposite decimal separator character
char oppositeDecimalSeparator = Detect.CharCross;
Console.WriteLine($"Opposite decimal separator: {oppositeDecimalSeparator}");
// Detect the decimal separator as an Enum value
DetectType decimalSeparatorEnum = Detect.Enum;
Console.WriteLine($"Decimal separator Enum: {decimalSeparatorEnum}");
// Detect the opposite decimal separator as an Enum value
DetectType oppositeDecimalSeparatorEnum = Detect.EnumCross;
Console.WriteLine($"Opposite decimal separator Enum: {oppositeDecimalSeparatorEnum}");
// Get the decimal separator as a string
string decimalSeparatorString = Detect.String;
Console.WriteLine($"Decimal separator string: {decimalSeparatorString}");
// Get the opposite decimal separator as a string
string oppositeDecimalSeparatorString = Detect.StringCross;
Console.WriteLine($"Opposite decimal separator string: {oppositeDecimalSeparatorString}");
- Tax
- Url
- Web
- Ping
- Port
- Text
- Time
- Hash
- Word
- Color
- Speed
- Lottery
- Storage
- Browser
- Unicode
- Password
- JavaScript
- Cryptology
- Typography
- Temperature
- Compression
- Decompression
- Cascading Style Sheets
- JavaScript Object Notation
- Hypertext Markup Language
- Extensible Markup Language
- Extensible HyperText Markup Language