Results for “Text validation & parsing”
Small, practical examples. Search by task or narrow things down below.
Treat dynamic regex input as literal text
Java: Use Pattern.quote so metacharacters in a search term lose their special meaning.
Java✓ Tested
Wrap an error with context
Wrap an error with context using a complete Go program with explicit sample inputs.
Go✓ Tested
Build a URL query string
Python: Use urlencode to percent-encode query parameter values correctly.
Python✓ Tested
Check a filename suffix
Java: Use endsWith for a case-sensitive literal suffix test.
Java✓ Tested
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 string prefix
Java: Use startsWith to check a literal Java prefix without a regular expression.
Java✓ Tested
Check an extension without case sensitivity
C#: Use an explicit ordinal case-insensitive comparison for a known filename suffix.
C#✓ Tested
Clamp a numeric setting to a valid range
Bash Scripts: Use arithmetic comparisons before applying a user-supplied bounded setting.
Bash Scripts✓ Tested
Count Unicode code points
Java: Use codePointCount when supplementary characters should count as one rather than two UTF-16 units.
Java✓ 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 range syntax
C#: C# range ends are exclusive; indices operate on UTF-16 code units.
C#✓ Tested