Results for “Text validation & formatting”
Small, practical examples. Search by task or narrow things down below.
Check a literal prefix with ordinal comparison
C#: Choose StringComparison.Ordinal when a prefix is a protocol token rather than culture-dependent text.
C#✓ Tested
Check a literal suffix in C++17
C++: Check lengths before subtracting to avoid an unsigned underflow.
C++✓ Tested
Check an extension without case sensitivity
C#: Use an explicit ordinal case-insensitive comparison for a known filename suffix.
C#✓ Tested
Encode and decode binary data as Base64
Python: Use Base64 when a text format must carry bytes; it is encoding, not encryption.
Python✓ Tested
Enumerate Unicode code points
C#: EnumerateRunes combines surrogate pairs into Unicode scalar values.
C#✓ Tested
Extract a substring with an explicit count
C++: The second substr argument is a length rather than an ending index.
C++✓ Tested
Extract a substring with range syntax
C#: C# range ends are exclusive; indices operate on UTF-16 code units.
C#✓ Tested
Extract named regex fields
Python: Use named capture groups to parse a known date-shaped identifier.
Python✓ Tested
Inspect a substring without allocating a copy
C++: A string_view refers to existing storage and must not outlive that storage.
C++✓ Tested
Iterate over all regular-expression matches
C++: A regex iterator yields successive matches without manually updating an offset.
C++✓ Tested
Normalize canonically equivalent Unicode strings
C#: Normalize to NFC before an ordinal comparison of equivalent character sequences.
C#✓ Tested
Normalize equivalent Unicode strings
Python: Normalize to NFC before comparing canonically equivalent text.
Python✓ Tested