Nix Language Quirks: Difference between revisions

Link to manual for indented strings. Also change capitalization to match manual
Tags: Mobile edit Mobile web edit
builtins.replaceStrings key match on "": Improve grammar and formatting
Tags: Mobile edit Mobile web edit
Line 113: Line 113:
</syntaxHighlight>
</syntaxHighlight>


Function allows match for "" in string. <code>[match]</code> gets checked sequentially, and when "" is checked - it always matches. And so - when "" is checked in always inserts the replacement, then next char in sting gets passed through, and the next char after that from the string gets processed.
The [https://noogle.dev/f/builtins/replaceStrings <code>builtins.replaceStrings</code>] function allows matching <code>""</code> in <code>string</code>. <code>[match]</code> gets checked sequentially, and when <code>""</code> is checked - it ''always'' matches. And so - when <code>""</code> is checked it ''always'' inserts the corresponding replacement from <code>[replace]</code>, then the next char in <code>string</code> gets inserted, and then the next char after that from <code>string</code> gets processed.
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
nix-repl> builtins.replaceStrings ["" "e"] [" " "i"] "Hello world"
nix-repl> builtins.replaceStrings ["" "e"] [" " "i"] "Hello world"