|
| 1 | +# String Array Functions |
| 2 | + |
| 3 | +- [`prefix`](#prefix) |
| 4 | +- [`suffix`](#suffix) |
| 5 | +- [`quote`](#quote) |
| 6 | +- [`squote`](#squote) |
| 7 | +- [`sep`](#sep) |
| 8 | + |
| 9 | +## `prefix` |
| 10 | + |
| 11 | +Adds a prefix to each element of the input array of primitive values. Equivalent to |
| 12 | +evaluating `"~{prefix}~{array[i]}"` for each `i` in `range(length(array))`. |
| 13 | + |
| 14 | +**Signatures** |
| 15 | + |
| 16 | +```wdl |
| 17 | +Array[String] prefix(String, Array[P]) |
| 18 | +``` |
| 19 | + |
| 20 | +**Parameters** |
| 21 | + |
| 22 | +1. **`String`**: The prefix to prepend to each element in the array. |
| 23 | +2. **`Array[P]`**: Array with a primitive element type. |
| 24 | + |
| 25 | +**Returns** |
| 26 | + |
| 27 | +1. An `Array[String]` with the prefixed elements of the input array. |
| 28 | + |
| 29 | +**Example** |
| 30 | + |
| 31 | +```wdl |
| 32 | +Array[String] names = ["John", "Jane", "world"] |
| 33 | +String greetings = prefix("Hello, ", names) |
| 34 | +# `greetings` now contains `["Hello, John", "Hello, Jane", "Hello, world"]`. |
| 35 | +``` |
| 36 | + |
| 37 | +## `suffix` |
| 38 | + |
| 39 | +Adds a suffix to each element of the input array of primitive values. Equivalent to |
| 40 | +evaluating `"~{array[i]}~{suffix}"` for each `i` in `range(length(array))`. |
| 41 | + |
| 42 | +**Signatures** |
| 43 | + |
| 44 | +```wdl |
| 45 | +Array[String] suffix(String, Array[P]) |
| 46 | +``` |
| 47 | + |
| 48 | +**Parameters** |
| 49 | + |
| 50 | +1. **`String`**: The suffix to append to each element in the array. |
| 51 | +2. **`Array[P]`**: Array with a primitive element type. |
| 52 | + |
| 53 | +**Returns** |
| 54 | + |
| 55 | +1. An `Array[String]` the suffixed elements of the input array. |
| 56 | + |
| 57 | +**Example** |
| 58 | + |
| 59 | +```wdl |
| 60 | +Array[String] names = ["John", "Jane"] |
| 61 | +String responses = suffix(" says 'hi!'", names) |
| 62 | +# `responses` now contains `["John says 'hi!'", "Jane says 'hi!'"]`. |
| 63 | +``` |
| 64 | + |
| 65 | +## `quote` |
| 66 | + |
| 67 | +Adds double-quotes (`"`) around each element of the input array of primitive values. |
| 68 | +Equivalent to evaluating `'"~{array[i]}"'` for each `i` in `range(length(array))`. |
| 69 | + |
| 70 | +**Signatures** |
| 71 | + |
| 72 | +```wdl |
| 73 | +Array[String] quote(Array[P]) |
| 74 | +``` |
| 75 | + |
| 76 | +**Parameters** |
| 77 | + |
| 78 | +1. **`Array[P]`**: Array with a primitive element type. |
| 79 | + |
| 80 | +**Returns** |
| 81 | + |
| 82 | +1. An `Array[String]` the double-quoted elements of the input array. |
| 83 | + |
| 84 | +**Example** |
| 85 | + |
| 86 | +```wdl |
| 87 | +Array[String] numbers = [1, 2, 3] |
| 88 | +String quoted = quote(numbers) |
| 89 | +# `quoted` now contains `["\"1\"", "\"2\"", "\"3\""]`. |
| 90 | +``` |
| 91 | + |
| 92 | +## `squote` |
| 93 | + |
| 94 | +Adds single-quotes (`'`) around each element of the input array of primitive values. |
| 95 | +Equivalent to evaluating `"'~{array[i]}'"` for each `i` in `range(length(array))`. |
| 96 | + |
| 97 | +**Signatures** |
| 98 | + |
| 99 | +```wdl |
| 100 | +Array[String] squote(Array[P]) |
| 101 | +``` |
| 102 | + |
| 103 | +**Parameters** |
| 104 | + |
| 105 | +1. **`Array[P]`**: Array with a primitive element type. |
| 106 | + |
| 107 | +**Returns** |
| 108 | + |
| 109 | +1. An `Array[String]` the single-quoted elements of the input array. |
| 110 | + |
| 111 | +**Example** |
| 112 | + |
| 113 | +```wdl |
| 114 | +Array[String] numbers = [1, 2, 3] |
| 115 | +String quoted = squote(numbers) |
| 116 | +# `quoted` now contains `["'1'", "'2'", "'3'"]`. |
| 117 | +``` |
| 118 | + |
| 119 | +## `sep` |
| 120 | + |
| 121 | +Concatenates the elements of an array together into a string with the given separator |
| 122 | +between consecutive elements. There are always `N-1` separators in the output string, |
| 123 | +where `N` is the length of the input array. A separator is never added after the last |
| 124 | +element. Returns an empty string if the array is empty. |
| 125 | + |
| 126 | +**Signatures** |
| 127 | + |
| 128 | +```wdl |
| 129 | +String sep(String, Array[P]) |
| 130 | +``` |
| 131 | + |
| 132 | +**Parameters** |
| 133 | + |
| 134 | +1. `String`: Separator string. |
| 135 | +2. `Array[P]`: Array of strings to concatenate. |
| 136 | + |
| 137 | +**Returns** |
| 138 | + |
| 139 | +1. A `String` with the concatenated elements of the array delimited by the separator |
| 140 | + string. |
| 141 | + |
| 142 | +**Example** |
| 143 | + |
| 144 | +```wdl |
| 145 | +Array[String] letters = ["a", "b", "c", "d"] |
| 146 | +String letters_with_commas = sep(", ", letters) |
| 147 | +# `letters_with_commas` now contains `"a, b, c, d"`. |
| 148 | +``` |
0 commit comments