Ben Chuanlong Du's Blog

It is never too late to learn.

Useful Rust Crates for String

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

indoc

The indoc crate provides a procedural macro for indented string literals. The indoc!() macro takes a multiline string literal and un-indents it at compile time so the leftmost non-space character …

String in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. In Golang, a string is implemented as a struct containing a data pointer (pointing to a read-only slice of bytes) and a length.

  2. Raw string literals, delimited by backticks (back quotes), are interpreted literally. They can contain line breaks, and backslashes have no special meaning.

Format a String in Python

str.format

An exception will be thrown if the value for a key in the string is not specified, which means that you must specify values for all keys. However, it is OK if you specify values for keys that do not exist in the string. That is you can specify values for more keys than needed.