|
|
| Zeile 1: |
Zeile 1: |
| = C# String-Operationen und wichtige Methoden = | | == Frontend Frameworks – Reifegrade == |
|
| |
|
| == Grundlagen ==
| | ; Tier-Definition (Kurzfassung) |
| ; Deklaration
| | * Tier 1: Weit verbreitet, stabil, Langzeitpflege, starkes Ökosystem |
| <syntaxhighlight lang="csharp">
| |
| string name = "Alice";
| |
| string leer = string.Empty;
| |
| </syntaxhighlight>
| |
|
| |
|
| ; Verkettung
| |
| <syntaxhighlight lang="csharp">
| |
| string full = vorname + " " + nachname;
| |
| string interp = $"{vorname} {nachname}";
| |
| var builder = new StringBuilder().Append(vorname).Append(' ').Append(nachname).ToString();
| |
| </syntaxhighlight>
| |
|
| |
|
| == Häufig genutzte Eigenschaften == | | {| class="wikitable sortable" |
| * Length – Anzahl der UTF-16 Codeeinheiten (nicht zwingend Benutzer-grafeme)
| | ! Tier !! Framework !! Kategorie !! Erstveröffentlichung !! Governance/Backing !! Release-/LTS-Kadenz !! Kurzbewertung |
| | |- |
| | | 1 || React || Bibliothek || 2013 || Meta + Community || regelmäßig || Dominantes Ökosystem, sehr stabil |
| | |- |
| | | 1 || Angular || Framework || 2016 || Google || LTS || Enterprise‑fokussiert, integrierter Stack |
| | |- |
| | | 1 || Vue.js || Framework || 2014 || Core‑Team + Community || regelmäßig || Reif, breite Adoption |
| | |- |
| | | 1 || Next.js || Meta‑Framework (React) || 2016 || Vercel || schnell || Produktionsreif, SSR/ISR/RSC |
|
| |
|
| == Vergleich ==
| | |} |
| <syntaxhighlight lang="csharp">
| |
| string.Equals(a, b); // Ordinal, case-sensitiv
| |
| string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
| |
| a.Equals(b, StringComparison.Ordinal);
| |
| a == b; // Wertvergleich
| |
| string.Compare(a, b, StringComparison.Ordinal);
| |
| </syntaxhighlight>
| |
| | |
| == Suchen ==
| |
| <syntaxhighlight lang="csharp">
| |
| str.Contains("abc", StringComparison.Ordinal);
| |
| str.StartsWith("pre", StringComparison.OrdinalIgnoreCase);
| |
| str.EndsWith("suf", StringComparison.Ordinal);
| |
| str.IndexOf("x", StringComparison.Ordinal);
| |
| str.LastIndexOf('.');
| |
| </syntaxhighlight>
| |
| | |
| == Extrahieren ==
| |
| <syntaxhighlight lang="csharp">
| |
| str.Substring(startIndex);
| |
| str.Substring(startIndex, length);
| |
| str[startIndex]; // einzelnes char
| |
| </syntaxhighlight>
| |
| | |
| == Teilstrings moderner (Span-Slicing) ==
| |
| <syntaxhighlight lang="csharp">
| |
| ReadOnlySpan<char> span = str.AsSpan();
| |
| var teil = span.Slice(5, 3); // vermeidet Kopie
| |
| </syntaxhighlight>
| |
| | |
| == Aufteilen & Zusammenfügen ==
| |
| <syntaxhighlight lang="csharp">
| |
| var parts = str.Split('.', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
| |
| string joined = string.Join(";", parts);
| |
| </syntaxhighlight>
| |
| | |
| == Trimmen ==
| |
| <syntaxhighlight lang="csharp">
| |
| str.Trim(); // Whitespace
| |
| str.TrimStart();
| |
| str.TrimEnd();
| |
| str.Trim('0'); // spezifische Zeichen
| |
| </syntaxhighlight>
| |
| | |
| == Ersetzen ==
| |
| <syntaxhighlight lang="csharp">
| |
| str.Replace("alt", "neu");
| |
| str.Replace('a', 'b');
| |
| Regex.Replace(str, "[0-9]+", "#");
| |
| </syntaxhighlight>
| |
| | |
| == Formatierung ==
| |
| <syntaxhighlight lang="csharp">
| |
| string.Format("Wert: {0:N2}", value);
| |
| $"Wert: {value:N2}";
| |
| value.ToString("N2", CultureInfo.InvariantCulture);
| |
| </syntaxhighlight>
| |
| | |
| == Groß/Kleinschreibung ==
| |
| <syntaxhighlight lang="csharp">
| |
| str.ToUpperInvariant();
| |
| str.ToLower(CultureInfo.CurrentCulture);
| |
| </syntaxhighlight>
| |
| | |
| == Einfügen & Entfernen ==
| |
| <syntaxhighlight lang="csharp">
| |
| str.Insert(index, "XYZ");
| |
| str.Remove(startIndex);
| |
| str.Remove(startIndex, count);
| |
| </syntaxhighlight>
| |
| | |
| == Pad (Auffüllen) ==
| |
| <syntaxhighlight lang="csharp">
| |
| "42".PadLeft(5, '0'); // 00042
| |
| "42".PadRight(5, '.'); // 42...
| |
| </syntaxhighlight>
| |
| | |
| == Zeichenprüfung ==
| |
| <syntaxhighlight lang="csharp">
| |
| char.IsLetterOrDigit(ch);
| |
| char.IsWhiteSpace(ch);
| |
| </syntaxhighlight>
| |
| | |
| == Immutable Hinweis ==
| |
| Strings sind unveränderlich. Viele Operationen erzeugen neue Instanzen. Für viele Verkettungen: StringBuilder.
| |
| | |
| == StringBuilder ==
| |
| <syntaxhighlight lang="csharp">
| |
| var sb = new StringBuilder(capacity:256)
| |
| .Append("Zeile ").AppendLine("1")
| |
| .AppendFormat("Wert={0}", 123);
| |
| string result = sb.ToString();
| |
| </syntaxhighlight>
| |
| | |
| == Sicherheitsrelevante Vergleiche ==
| |
| <syntaxhighlight lang="csharp">
| |
| CryptographicOperations.FixedTimeEquals(
| |
| MemoryMarshal.AsBytes("secret"u8),
| |
| MemoryMarshal.AsBytes(eingabe.AsSpan()));
| |
| </syntaxhighlight>
| |
| | |
| == Null / Empty / WhiteSpace ==
| |
| <syntaxhighlight lang="csharp">
| |
| string.IsNullOrEmpty(str);
| |
| string.IsNullOrWhiteSpace(str);
| |
| </syntaxhighlight>
| |
| | |
| == Interpolated String Handler (Performance) ==
| |
| <syntaxhighlight lang="csharp">
| |
| [InterpolatedStringHandler]
| |
| public ref struct LogHandler {
| |
| // eigener Handler für Logging
| |
| }
| |
| </syntaxhighlight>
| |
| | |
| == Raw String Literals (C# 11) ==
| |
| <syntaxhighlight lang="csharp">
| |
| string json = """
| |
| {
| |
| "id": 1,
| |
| "name": "Alice"
| |
| }
| |
| """;
| |
| </syntaxhighlight>
| |
| | |
| == Escapes ==
| |
| <syntaxhighlight lang="csharp">
| |
| string pfad = @"C:\Temp\log.txt";
| |
| string zeile = "Text\nNeue Zeile\tTab";
| |
| </syntaxhighlight>
| |
| | |
| == Normalisierung (Unicode) ==
| |
| <syntaxhighlight lang="csharp">
| |
| string norm = str.Normalize(NormalizationForm.FormC);
| |
| </syntaxhighlight>
| |
| | |
| == Split vs Span ==
| |
| Für Hochleistung: str.AsSpan().Split(...) (ab .NET 8: MemoryExtensions.Split)
| |
| | |
| == Zusammenfassung ==
| |
| Kurzliste: Length, Indexer, Substring, Contains, StartsWith, EndsWith, IndexOf, Split, Join, Trim*, Replace, Insert, Remove, PadLeft/Right, ToUpper*/ToLower*, Format/$-Interpolation, Equals/Compare, Normalize, StringBuilder.
| |
Frontend Frameworks – Reifegrade
- Tier-Definition (Kurzfassung)
- Tier 1: Weit verbreitet, stabil, Langzeitpflege, starkes Ökosystem
| Tier |
Framework |
Kategorie |
Erstveröffentlichung |
Governance/Backing |
Release-/LTS-Kadenz |
Kurzbewertung
|
| 1 |
React |
Bibliothek |
2013 |
Meta + Community |
regelmäßig |
Dominantes Ökosystem, sehr stabil
|
| 1 |
Angular |
Framework |
2016 |
Google |
LTS |
Enterprise‑fokussiert, integrierter Stack
|
| 1 |
Vue.js |
Framework |
2014 |
Core‑Team + Community |
regelmäßig |
Reif, breite Adoption
|
| 1 |
Next.js |
Meta‑Framework (React) |
2016 |
Vercel |
schnell |
Produktionsreif, SSR/ISR/RSC
|