.NET API Reference

System.Net.Http.Headers // UnicodeCategoryHeaderValue

System.Net.Http.Headers

UnicodeCategoryHeaderValue

Represents a Unicode category header value.

Summary

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.

Constructors

Methods

Properties

Example Usage

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
        }
    }
}