Repository navigation
EN CSharp Strings
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
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.
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.
ClassicUO — Bad Newbie & C# Scripts IDE