FIND YOUR NEXT FEW LINES

Results for “Functions & parameter validation”

Small, practical examples. Search by task or narrow things down below.

202 snippets foundClear filters
PowerShellDates & numeric validation

Reject NaN and infinite values

PowerShell: Double.IsFinite excludes numeric values unsuitable for ordinary bounded calculations.

PowerShell✓ Tested
GoErrors & validation

Reject non-finite numeric input

Reject non-finite numeric input using a complete Go program with explicit sample inputs.

Go✓ Tested
Bash ScriptsVariables & text

Remove a filename extension

Keep the path while removing its final extension.

filename✓ Tested
PythonText validation & encoding

Remove a known prefix safely

Python: Use removeprefix instead of lstrip when removing a literal prefix rather than a set of characters.

Python✓ Tested
Bash ScriptsParameter expansion

Remove a known prefix with a shell pattern

Bash Scripts: The hash expansion removes the shortest matching prefix without changing the original variable.

Bash Scripts✓ Tested
PythonText validation & encoding

Remove a known suffix safely

Python: Use removesuffix to remove only a matching ending.

Python✓ Tested
JavaText validation & formatting

Repeat text a fixed number of times

Java: Use String.repeat with a nonnegative repetition count.

Java✓ Tested
C++Text validation & parsing

Replace text using captured regex groups

C++: Numbered replacement groups can rearrange a known two-part name.

C++✓ Tested
ReactForms & validation

Reset controlled form state

Reset controlled form state with a small React component and explicit browser behavior.

React✓ Tested
CStructures & function interfaces

Return a status separately from a calculated result

C: An output pointer lets a function return success or failure independently of its numeric result.

C✓ Tested
PowerShellDates & numeric validation

Round a decimal with a chosen midpoint rule

PowerShell: Use decimal input and an explicit rounding policy for a reproducible decimal result.

PowerShell✓ Tested
PythonFunctions & error handling

Run cleanup around a custom context

Python: Use try/finally inside a contextmanager so cleanup runs even on failure.

Python✓ Tested