|
| 1 | +let |
| 2 | + /* |
| 3 | + About: Join a string with a delimiter, prefix, and suffix |
| 4 | + It was written as an example for using optional record parameters |
| 5 | + |
| 6 | + |
| 7 | + For more advanced joins, checkout these collections of functions: |
| 8 | + - Write.Html.module.pq |
| 9 | + - String.Builder.module.pq |
| 10 | + |
| 11 | + */ |
| 12 | + Text.JoinString = (strings as list, optional options as record) as text => let |
| 13 | + Prefix = options[Prefix]? ?? "", |
| 14 | + Suffix = options[Suffix]? ?? "", |
| 15 | + Delimiter = options[Delimiter]? ?? "," |
| 16 | + in |
| 17 | + Prefix & Text.Combine( strings, Delimiter ) & Suffix |
| 18 | +in |
| 19 | + Text.JoinString |
| 20 | + |
| 21 | +// Examples = [ |
| 22 | + |
| 23 | +// names = {"Jen", "Hubert", "Nobody", "Somebody" }, |
| 24 | + |
| 25 | +// Default = Text.JoinString( names ) , |
| 26 | + |
| 27 | +// AsCsv = Text.JoinString( names, [ Delimiter = ", "] ), |
| 28 | + |
| 29 | +// AsTablePipes = Text.JoinString( names, [ |
| 30 | +// Prefix = "| ", Delimiter = " | ", Suffix = " |" ] ), |
| 31 | + |
| 32 | +// AsBullets = Text.JoinString( names, [ |
| 33 | +// Prefix = " #(2022) ", |
| 34 | +// Delimiter = " #(cr,lf) #(2022) " |
| 35 | +// ]) |
| 36 | +// ] |
| 37 | +// in |
| 38 | +// Examples |
0 commit comments