Results for “validation”
Small, practical examples. Search by task or narrow things down below.
Build text efficiently in a loop
Java: Append to StringBuilder when constructing a string incrementally.
Java✓ Tested
Build text incrementally with StringBuilder
C#: Append fragments instead of repeatedly concatenating intermediate strings in a loop.
C#✓ Tested
Calculate a page count with ceiling division
JavaScript: Use Math.ceil for a nonnegative item count and a positive page size.
JavaScript✓ Tested
Calculate a page count with ceiling division
TypeScript: Use Math.ceil for a nonnegative item count and a positive page size.
TypeScript✓ Tested
Calculate integers beyond Number’s precise range
JavaScript: Use BigInt operands together to avoid precision loss.
JavaScript✓ Tested
Calculate integers beyond Number’s precise range
TypeScript: Use BigInt operands together to avoid precision loss.
TypeScript✓ Tested
Check a filename suffix
Java: Use endsWith for a case-sensitive literal suffix test.
Java✓ Tested
Check a literal prefix in C++17
C++: Use string compare because starts_with was introduced after C++17.
C++✓ 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 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