FIND YOUR NEXT FEW LINES

Results for “Strings & text”

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

474 snippets foundClear filters
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
PythonText validation & encoding

Remove a known suffix safely

Python: Use removesuffix to remove only a matching ending.

Python✓ Tested
RustStrings & Unicode

Remove a prefix only when it matches

Remove a prefix only when it matches in a complete Rust program using the standard library.

Rust✓ Tested
Bash ScriptsText parsing & arithmetic

Remove a trailing carriage return from a line

Bash Scripts: Use an ANSI-C quoted carriage return as the suffix pattern.

Bash Scripts✓ Tested
Linux CommandsTransforming text

Remove blank or whitespace-only lines

Linux Commands: Use a POSIX character class so tabs and spaces are handled together.

Linux Commands✓ Tested
Linux CommandsTransforming text

Remove carriage-return characters

Linux Commands: Use tr -d to remove CR characters from Windows-style line endings.

Linux Commands✓ Tested
Linux CommandsTransforming text

Reorder fields with a capture group

Linux Commands: Use extended regular expressions and backreferences to rearrange a known format.

Linux Commands✓ Tested
JavaScriptText handling & Unicode

Repeat a string a fixed number of times

JavaScript: String.repeat requires a nonnegative finite repetition count.

JavaScript✓ Tested
TypeScriptText handling & Unicode

Repeat a string a fixed number of times

TypeScript: String.repeat requires a nonnegative finite repetition count.

TypeScript✓ Tested
SQLText cleanup & matching

Replace a literal substring

SQL: REPLACE performs a literal replacement rather than a regular-expression substitution.

SQL✓ Tested
SQL ServerText cleanup & matching

Replace a literal substring

SQL Server: REPLACE performs a literal replacement rather than a regular-expression substitution.

SQL Server✓ Tested
PostgresText cleanup & matching

Replace a literal substring

Postgres: REPLACE performs a literal replacement rather than a regular-expression substitution.

Postgres✓ Tested