#strings Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
PHP Convert Camel Case ↔ Snake Case
Convert between camelCase and snake_case identifiers. Handy when mapping JS API responses (camelCase) into PHP database column names (snake_case) and vice versa.
TypeScript Template Tag for Safe HTML
Build HTML strings with a tagged template literal that auto-escapes every interpolated value. Eliminates a class of XSS bugs without pulling in a templating library.
Go strings package essentials
The most-reached-for functions in the `strings` package: Split, Contains, TrimSpace, ToLower/Upper, Replace, Index, HasPrefix/Suffix.
Go text/template — Simple Templating
Stdlib templating with `{{.Field}}` placeholders, range loops, if/else, and function pipelines. Safe alternative for non-HTML text (e.g. emails, config files).
PHP Email Address Obfuscator
Render an email address as HTML that is human-readable but resistant to naive scraping bots. Uses entity encoding and an optional Caesar-style ROT for the mailto link.
TypeScript Slugify (Unicode-aware)
Turn any string into a URL-safe slug. Uses Intl normalize + diacritic stripping so "Café" becomes "cafe". No external dependency.
Go strings.Builder — Efficient Concatenation
Building strings with `+` allocates O(n²) memory. `strings.Builder` writes to an internal buffer with a single final allocation — orders of magnitude faster in loops.
Bash Heredoc with Variable Interpolation Control
Heredocs are the cleanest way to embed multi-line text. Unquote the delimiter to allow variable expansion; QUOTE it to keep the body literal (no $foo expansion).
Python textwrap dedent + fill (Multi-line Strings)
`textwrap.dedent` strips common leading whitespace from a triple-quoted string — finally, you can indent multiline strings inside functions without breaking the formatting. `fill` wraps to a max width.
Rust String vs &str — The Cheat Sheet
`String` is an owned, growable heap allocation; `&str` is a borrowed view into a UTF-8 buffer. Function params should usually take `&str`; return types use `String` when ownership is needed.
Go strconv — String ↔ Number Conversions
`strconv.Atoi` / `Itoa` for the common int<->string case; `ParseFloat`, `ParseBool`, `Quote` for everything else. Always handle the error — strings can be anything.
TypeScript Capitalize / Title-Case
Two common case transforms. `capitalize` for the first letter only; `titleCase` for every word, with small "stop words" left lowercase except at the edges.
Bash Trim Whitespace from String
Strip leading and trailing whitespace without spawning sed or awk. Uses extglob + parameter expansion — much faster in tight loops than a subshell.
Python Word-Safe Truncate
Cap a string at `max_len` chars without splitting a word; append an ellipsis when truncated. Backs off to the last space if cutting mid-word would happen.
Python Mask Sensitive Strings (PII)
Mask the middle of a string while keeping a few chars at each end. Useful for displaying credit cards, emails, or API keys in UI / logs without leaking the whole value.
Python Slugify (unicodedata, zero deps)
Convert any string to a URL-safe slug using only stdlib. Normalizes Unicode (NFKD), strips combining marks, lowercases, replaces non-alphanumerics with a separator.
Bash Split String into Array on Delimiter
Use IFS + read or readarray to split safely. Don't use word-splitting tricks — they break on edge cases (empty fields, spaces in values).
PHP Highlight Search Term in Text
Wrap every case-insensitive occurrence of a search term in <mark> tags for quick visual highlighting in search results. Properly escapes HTML so user input cannot inject markup.