Skip to content

EN CSharp Strings

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

Strings, formatting and regular expressions

Manual C# · Examples UO

Strings are immutable. Ordinary strings use escape sequences; verbatim strings @"..." preserve backslashes; interpolated strings $"..." insert expressions; raw strings use multiple quote characters. Numeric formatting depends on the selected culture.

Simple example (Example.cs)

Save this example separately as Example.cs. Run it independently of the other examples on this page.

Example.cs:

// PROJECT-EXAMPLE
string name = "ore";
System.Console.WriteLine(name.ToUpperInvariant());
System.Console.WriteLine($"Length={name.Length}");

Result:

ORE
Length=3
string path = @"C:\Games\UltimaOnline";
int amount = 12;
string message = $"Amount={amount:D3}";
UO.Print(message);
UO.Print(path);
using System.Text.RegularExpressions;
string text = "HP: 42";
Match match = Regex.Match(text, @"\d+");
if (match.Success && int.TryParse(match.Value, out int hp))
{
    UO.Print(hp.ToString());
}

To accumulate large text, use StringBuilder. For comparisons, explicitly select StringComparison or StringComparer. char does not always represent the entire character visible to the user; Consider Rune and text elements when processing Unicode.

Official Documentation: Strings, Formatting, and Regular Expressions - Microsoft Learn.

Clone this wiki locally