Represents a Unicode category header value.
The UnicodeCategoryHeaderValue class provides a way to parse and represent Unicode category values used in HTTP headers. This class is immutable and provides static methods for parsing and creating instances.
Initializes a new instance of the UnicodeCategoryHeaderValue class with the specified Unicode category.
Parameters:
category: The Unicode category string.Parses a Unicode category header value string and returns an instance of the UnicodeCategoryHeaderValue class.
Parameters:
value: The string to parse.Returns: A UnicodeCategoryHeaderValue instance.
Throws: FormatException if the string is not a valid Unicode category header value.
Tries to parse a Unicode category header value string and returns a value that indicates whether the parsing succeeded.
Parameters:
value: The string to parse.parsedValue: When this method returns, contains the parsed UnicodeCategoryHeaderValue if the parsing succeeded, or null if the parsing failed.Returns: true if the string was parsed successfully; otherwise, false.
Returns the string representation of the Unicode category header value.
Returns: The string representation of the Unicode category.
Gets the Unicode category string.
Returns: The Unicode category string.
using System;
using System.Net.Http.Headers;
public class Example
{
public static void Main(string[] args)
{
// Parsing a known category
string headerValue = "Lu"; // Uppercase Letter
try
{
UnicodeCategoryHeaderValue unicodeCategory = UnicodeCategoryHeaderValue.Parse(headerValue);
Console.WriteLine($$"Parsed category: {unicodeCategory.Category}"); // Output: Parsed category: Lu
// Using ToString()
Console.WriteLine($$"String representation: {unicodeCategory.ToString()}"); // Output: String representation: Lu
}
catch (FormatException ex)
{
Console.WriteLine($"Error parsing: {ex.Message}");
}
// Trying to parse an invalid value
string invalidValue = "XYZ";
UnicodeCategoryHeaderValue parsedCategory;
if (UnicodeCategoryHeaderValue.TryParse(invalidValue, out parsedCategory))
{
Console.WriteLine($$"Successfully parsed: {parsedCategory.Category}");
}
else
{
Console.WriteLine($"Failed to parse: {invalidValue}"); // Output: Failed to parse: XYZ
}
}
}