Results for “Strings & text”
Small, practical examples. Search by task or narrow things down below.
Check a literal string prefix
C: strncmp compares at most the prefix length; both inputs must be valid strings.
C✓ Tested
Check a literal suffix in C++17
C++: Check lengths before subtracting to avoid an unsigned underflow.
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
Check an external process exit status explicitly
PowerShell: LASTEXITCODE reports a native child exit code independently of ordinary PowerShell cmdlet errors.
PowerShell✓ Tested
Check whether a command can be resolved
PowerShell: Get-Command with a local error override supports an expected missing-command lookup.
PowerShell✓ Tested
Clamp a numeric setting to a valid range
Bash Scripts: Use arithmetic comparisons before applying a user-supplied bounded setting.
Bash Scripts✓ Tested
Collapse repeated spaces
Linux Commands: Use tr -s when repeated occurrences of a character should become one.
Linux Commands✓ Tested
Compare binary buffers including zero bytes
C: memcmp checks an explicit byte length rather than stopping at a string terminator.
C✓ Tested
Convert tab stops to spaces
Linux Commands: Use expand with a fixed tab width when preparing plain-text alignment.
Linux Commands✓ Tested
Copy a file into an image
Include a small application file during the build.
Dockerfile✓ Tested
Copy a string with a guaranteed terminator
Arduino / C: Reserve one character for the terminator when copying a bounded string.
Arduino / C✓ Tested