Results for “Strings & literal text”
Small, practical examples. Search by task or narrow things down below.
Replace every occurrence in a string
Substitute text directly with Bash parameter expansion.
replace✓ Tested
Replace repeated whitespace
Normalize runs of whitespace to one space.
regex✓ Tested
Represent a finite set of states
Java: Use an enum to prevent arbitrary strings from representing application states.
Java✓ Tested
Reuse colors with custom properties
Define a CSS custom property and use it for text color.
CSS✓ Tested
Reverse a string
Reverse a byte string in place with std::reverse.
C++✓ Tested
Round a decimal using an explicit midpoint rule
C#: Use decimal literals for decimal arithmetic and choose the midpoint rounding behavior.
C#✓ Tested
Round a decimal with an explicit rule
Java: Construct BigDecimal from text to avoid importing a binary floating-point approximation.
Java✓ Tested
Round decimal amounts explicitly
Python: Build Decimal values from strings and choose a rounding rule explicitly.
Python✓ Tested
Run a first SELECT query
SQL: Return a literal value without creating a table.
SQL✓ Tested
Run a first SELECT query
SQL Server: Return a literal value without creating a table.
SQL Server✓ Tested
Run a first SELECT query
Postgres: Return a literal value without creating a table.
Postgres✓ Tested
Run a first SELECT query
SQLite: Return a literal value without creating a table.
SQLite✓ Tested