Skip to content

StringOperations

Namespace for operations on strings.

This class cannot be instantiated directly. It can only be accessed using the str attribute of a cell.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", "cd"]);
    out column.transform((cell) -> cell.str.toUppercase());
}
Stub code in StringOperations.sdsstub

 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
class StringOperations {
    /**
     * Check if the string contains the substring.
     *
     * @param substring The substring to search for.
     *
     * @result contains Whether the string contains the substring.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "cd", null]);
     *     out column.transform((cell) -> cell.str.contains("b"));
     * }
     */
    @Pure
    fun contains(
        substring: ConvertibleToStringCell
    ) -> contains: Cell<Boolean?>

    /**
     * Check if the string ends with the suffix.
     *
     * @param suffix The expected suffix.
     *
     * @result cell Whether the string ends with the suffix.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.endsWith("b"));
     * }
     */
    @Pure
    @PythonName("ends_with")
    fun endsWith(
        suffix: ConvertibleToStringCell
    ) -> cell: Cell<Boolean?>

    /**
     * Get the index of the first occurrence of the substring.
     *
     * @param substring The substring to search for.
     *
     * @result cell The index of the first occurrence of the substring. If the substring is not found, null is returned.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "cd", null]);
     *     out column.transform((cell) -> cell.str.indexOf("b"));
     * }
     */
    @Pure
    @PythonName("index_of")
    fun indexOf(
        substring: ConvertibleToStringCell
    ) -> cell: Cell<Int?>

    /**
     * Get the number of characters.
     *
     * @param optimizeForAscii Greatly speed up this operation if the string is ASCII-only. If the string contains non-ASCII characters,
     * this option will return incorrect results, though.
     *
     * @result cell The number of characters.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["", "a", "abc", null]);
     *     out column.transform((cell) -> cell.str.length());
     * }
     */
    @Pure
    fun length(
        @PythonName("optimize_for_ascii") optimizeForAscii: Boolean = false
    ) -> cell: Cell<Int?>

    /**
     * Pad the end of the string with the given character until it has the given length.
     *
     * @param length The minimum length of the string. If the string is already at least as long, it is returned unchanged. Must
     * be greater than or equal to 0.
     * @param character How to pad the string. Must be a single character.
     *
     * @result cell The padded string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bcde", null]);
     *     out column.transform((cell) -> cell.str.padEnd(3));
     *     out column.transform((cell) -> cell.str.padEnd(3, character="~"));
     * }
     */
    @Pure
    @PythonName("pad_end")
    fun padEnd(
        const length: Int,
        character: String = " "
    ) -> cell: Cell<String?> where {
        length >= 0
    }

    /**
     * Pad the start of the string with the given character until it has the given length.
     *
     * @param length The minimum length of the string. If the string is already at least as long, it is returned unchanged. Must
     * be greater than or equal to 0.
     * @param character How to pad the string. Must be a single character.
     *
     * @result cell The padded string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bcde", null]);
     *     out column.transform((cell) -> cell.str.padStart(3));
     *     out column.transform((cell) -> cell.str.padStart(3, character="~"));
     * }
     */
    @Pure
    @PythonName("pad_start")
    fun padStart(
        const length: Int,
        character: String = " "
    ) -> cell: Cell<String?> where {
        length >= 0
    }

    /**
     * Remove a prefix from the string. Strings without the prefix are not changed.
     *
     * @param prefix The prefix to remove.
     *
     * @result cell The string without the prefix.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.removePrefix("a"));
     * }
     */
    @Pure
    @PythonName("remove_prefix")
    fun removePrefix(
        prefix: ConvertibleToStringCell
    ) -> cell: Cell<String?>

    /**
     * Remove a suffix from the string. Strings without the suffix are not changed.
     *
     * @param suffix The suffix to remove.
     *
     * @result cell The string without the suffix.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.removeSuffix("b"));
     * }
     */
    @Pure
    @PythonName("remove_suffix")
    fun removeSuffix(
        suffix: ConvertibleToStringCell
    ) -> cell: Cell<String?>

    /**
     * Repeat the string a number of times.
     *
     * @param count The number of times to repeat the string. Must be greater than or equal to 0.
     *
     * @result cell The repeated string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.repeat(2));
     * }
     */
    @Pure
    fun repeat(
        count: ConvertibleToIntCell
    ) -> cell: Cell<String?>

    /**
     * Replace all occurrences of the old substring with the new substring.
     *
     * @param old The substring to replace.
     * @param new The substring to replace with.
     *
     * @result cell The string with all occurrences replaced.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.replaceAll("b", "z"));
     * }
     */
    @Pure
    @PythonName("replace_all")
    fun replaceAll(
        old: ConvertibleToStringCell,
        new: ConvertibleToStringCell
    ) -> cell: Cell<String?>

    /**
     * Reverse the string.
     *
     * @result cell The reversed string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.reverse());
     * }
     */
    @Pure
    fun reverse() -> cell: Cell<String?>

    /**
     * Get a slice of the string.
     *
     * @param start The start index of the slice. Nonnegative indices are counted from the beginning (starting at 0), negative
     * indices from the end (starting at -1).
     * @param length The length of the slice. If None, the slice contains all characters starting from `start`. Must greater than
     * or equal to 0.
     *
     * @result cell The sliced string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["abc", "de", null]);
     *     out column.transform((cell) -> cell.str.slice(start = 1));
     *     out column.transform((cell) -> cell.str.slice(start = 1, length = 1));
     * }
     */
    @Pure
    fun slice(
        start: ConvertibleToIntCell = 0,
        length: ConvertibleToIntCell = null
    ) -> cell: Cell<String?>

    /**
     * Check if the string starts with the prefix.
     *
     * @param prefix The expected prefix.
     *
     * @result cell Whether the string starts with the prefix.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.startsWith("a"));
     * }
     */
    @Pure
    @PythonName("starts_with")
    fun startsWith(
        prefix: ConvertibleToStringCell
    ) -> cell: Cell<Boolean?>

    /**
     * Remove leading and trailing characters.
     *
     * @param characters The characters to remove. If None, whitespace is removed.
     *
     * @result cell The stripped string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["  ab  ", "~ bc ~", null]);
     *     out column.transform((cell) -> cell.str.strip());
     *     out column.transform((cell) -> cell.str.strip(characters=" ~"));
     * }
     */
    @Pure
    fun strip(
        characters: ConvertibleToStringCell = null
    ) -> cell: Cell<String?>

    /**
     * Remove trailing characters.
     *
     * @param characters The characters to remove. If None, whitespace is removed.
     *
     * @result cell The stripped string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["  ab  ", "~ bc ~", null]);
     *     out column.transform((cell) -> cell.str.stripEnd());
     *     out column.transform((cell) -> cell.str.stripEnd(characters=" ~"));
     * }
     */
    @Pure
    @PythonName("strip_end")
    fun stripEnd(
        characters: ConvertibleToStringCell = null
    ) -> cell: Cell<String?>

    /**
     * Remove leading characters.
     *
     * @param characters The characters to remove. If None, whitespace is removed.
     *
     * @result cell The stripped string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["  ab  ", "~ bc ~", null]);
     *     out column.transform((cell) -> cell.str.stripStart());
     *     out column.transform((cell) -> cell.str.stripStart(characters=" ~"));
     * }
     */
    @Pure
    @PythonName("strip_start")
    fun stripStart(
        characters: ConvertibleToStringCell = null
    ) -> cell: Cell<String?>

    /**
     * Convert a string to a date.
     *
     * The `format` parameter controls the presentation. It can be `"iso"` to target ISO 8601 or a custom string. The
     * custom string can contain fixed specifiers (see below), which are replaced with the corresponding values. The
     * specifiers are case-sensitive and always enclosed in curly braces. Other text is included in the output
     * verbatim. To include a literal opening curly brace, use `\{`, and to include a literal backslash, use `\\`.
     *
     * The following specifiers are available:
     *
     * - `{Y}`, `{_Y}`, `{^Y}`: Year (zero-padded to four digits, space-padded to four digits, no padding).
     * - `{Y99}`, `{_Y99}`, `{^Y99}`: Year modulo 100 (zero-padded to two digits, space-padded to two digits, no
     *   padding).
     * - `{M}`, `{_M}`, `{^M}`: Month (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{M-full}`: Full name of the month (e.g. "January").
     * - `{M-short}`: Abbreviated name of the month with three letters (e.g. "Jan").
     * - `{W}`, `{_W}`, `{^W}`: Week number as defined by ISO 8601 (zero-padded to two digits, space-padded to two
     *   digits, no padding).
     * - `{D}`, `{_D}`, `{^D}`: Day of the month (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{DOW}`: Day of the week as defined by ISO 8601 (1 = Monday, 7 = Sunday).
     * - `{DOW-full}`: Full name of the day of the week (e.g. "Monday").
     * - `{DOW-short}`: Abbreviated name of the day of the week with three letters (e.g. "Mon").
     * - `{DOY}`, `{_DOY}`, `{^DOY}`: Day of the year, ranging from 1 to 366 (zero-padded to three digits, space-padded
     *   to three digits, no padding).
     *
     * The specifiers follow certain conventions:
     *
     * - If a component may be formatted in multiple ways, we use shorter specifiers for ISO 8601. Specifiers for
     *   other formats have a prefix (same value with different padding, see below) or suffix (other differences).
     * - By default, value are zero-padded, where applicable.
     * - A leading underscore (`_`) means the value is space-padded.
     * - A leading caret (`^`) means the value has no padding (think of the caret in regular expressions).
     *
     * @param format The format to use.
     *
     * @result cell The parsed date.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["1999-02-03", "03.02.2001", "abc", null]);
     *     out column.transform((cell) -> cell.str.toDate());
     *     out column.transform((cell) -> cell.str.toDate(format="{D}.{M}.{Y}"));
     * }
     */
    @Pure
    @PythonName("to_date")
    fun toDate(
        format: String? = "iso"
    ) -> cell: Cell<Date?>

    /**
     * Convert a string to a datetime.
     *
     * The `format` parameter controls the presentation. It can be `"iso"` to target ISO 8601 or a custom string. The
     * custom string can contain fixed specifiers (see below), which are replaced with the corresponding values. The
     * specifiers are case-sensitive and always enclosed in curly braces. Other text is included in the output
     * verbatim. To include a literal opening curly brace, use `\{`, and to include a literal backslash, use `\\`.
     *
     * The following specifiers for _date components_ are available for **datetime** and **date**:
     *
     * - `{Y}`, `{_Y}`, `{^Y}`: Year (zero-padded to four digits, space-padded to four digits, no padding).
     * - `{Y99}`, `{_Y99}`, `{^Y99}`: Year modulo 100 (zero-padded to two digits, space-padded to two digits, no
     *   padding).
     * - `{M}`, `{_M}`, `{^M}`: Month (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{M-full}`: Full name of the month (e.g. "January").
     * - `{M-short}`: Abbreviated name of the month with three letters (e.g. "Jan").
     * - `{W}`, `{_W}`, `{^W}`: Week number as defined by ISO 8601 (zero-padded to two digits, space-padded to two
     *   digits, no padding).
     * - `{D}`, `{_D}`, `{^D}`: Day of the month (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{DOW}`: Day of the week as defined by ISO 8601 (1 = Monday, 7 = Sunday).
     * - `{DOW-full}`: Full name of the day of the week (e.g. "Monday").
     * - `{DOW-short}`: Abbreviated name of the day of the week with three letters (e.g. "Mon").
     * - `{DOY}`, `{_DOY}`, `{^DOY}`: Day of the year, ranging from 1 to 366 (zero-padded to three digits, space-padded
     *   to three digits, no padding).
     *
     * The following specifiers for _time components_ are available for **datetime** and **time**:
     *
     * - `{h}`, `{_h}`, `{^h}`: Hour (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{h12}`, `{_h12}`, `{^h12}`: Hour in 12-hour format (zero-padded to two digits, space-padded to two digits, no
     *   padding).
     * - `{m}`, `{_m}`, `{^m}`: Minute (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{s}`, `{_s}`, `{^s}`: Second (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{.f}`: Fractional seconds with a leading decimal point.
     * - `{ms}`: Millisecond (zero-padded to three digits).
     * - `{us}`: Microsecond (zero-padded to six digits).
     * - `{ns}`: Nanosecond (zero-padded to nine digits).
     * - `{AM/PM}`: AM or PM (uppercase).
     * - `{am/pm}`: am or pm (lowercase).
     *
     * The following specifiers are available for **datetime** only:
     *
     * - `{z}`: Offset of the timezone from UTC without a colon (e.g. "+0000").
     * - `{:z}`: Offset of the timezone from UTC with a colon (e.g. "+00:00").
     * - `{u}`: The UNIX timestamp in seconds.
     *
     * The specifiers follow certain conventions:
     *
     * - Generally, date components use uppercase letters and time components use lowercase letters.
     * - If a component may be formatted in multiple ways, we use shorter specifiers for ISO 8601. Specifiers for
     *   other formats have a prefix (same value with different padding, see below) or suffix (other differences).
     * - By default, value are zero-padded, where applicable.
     * - A leading underscore (`_`) means the value is space-padded.
     * - A leading caret (`^`) means the value has no padding (think of the caret in regular expressions).
     *
     * @param format The format to use.
     *
     * @result cell The parsed datetime.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["1999-12-31T01:02:03Z", "12:30 Jan 23 2024", "abc", null]);
     *     out column.transform((cell) -> cell.str.toDatetime());
     *     out column.transform((cell) -> cell.str.toDatetime(
     *         format="{h}:{m} {M-short} {D} {Y}"
     *     ));
     * }
     */
    @Pure
    @PythonName("to_datetime")
    fun toDatetime(
        format: String? = "iso"
    ) -> cell: Cell<Datetime?>

    /**
     * Convert the string to a float.
     *
     * @result cell The float value. If the string cannot be converted to a float, null is returned.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["1", "1.5", "abc", null]);
     *     out column.transform((cell) -> cell.str.toFloat());
     * }
     */
    @Pure
    @PythonName("to_float")
    fun toFloat() -> cell: Cell<Float?>

    /**
     * Convert the string to an integer.
     *
     * @param base The base of the integer.
     *
     * @result cell The integer value. If the string cannot be converted to an integer, null is returned.
     *
     * @example
     * pipeline example {
     *     val column1 = Column("a", ["1", "10", "abc", null]);
     *     out column1.transform((cell) -> cell.str.toInt());
     * }
     *
     * @example
     * pipeline example {
     *     val column2 = Column("a", ["1", "10", "abc", null]);
     *     out column2.transform((cell) -> cell.str.toInt(base = 2));
     * }
     */
    @Pure
    @PythonName("to_int")
    fun toInt(
        base: ConvertibleToIntCell = 10
    ) -> cell: Cell<Int?>

    /**
     * Convert the string to lowercase.
     *
     * @result cell The lowercase string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["AB", "BC", null]);
     *     out column.transform((cell) -> cell.str.toLowercase());
     * }
     */
    @Pure
    @PythonName("to_lowercase")
    fun toLowercase() -> cell: Cell<String?>

    /**
     * Convert a string to a time.
     *
     * The `format` parameter controls the presentation. It can be `"iso"` to target ISO 8601 or a custom string. The
     * custom string can contain fixed specifiers (see below), which are replaced with the corresponding values. The
     * specifiers are case-sensitive and always enclosed in curly braces. Other text is included in the output
     * verbatim. To include a literal opening curly brace, use `\{`, and to include a literal backslash, use `\\`.
     *
     * The following specifiers are available:
     *
     * - `{h}`, `{_h}`, `{^h}`: Hour (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{h12}`, `{_h12}`, `{^h12}`: Hour in 12-hour format (zero-padded to two digits, space-padded to two digits, no
     *   padding).
     * - `{m}`, `{_m}`, `{^m}`: Minute (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{s}`, `{_s}`, `{^s}`: Second (zero-padded to two digits, space-padded to two digits, no padding).
     * - `{.f}`: Fractional seconds with a leading decimal point.
     * - `{ms}`: Millisecond (zero-padded to three digits).
     * - `{us}`: Microsecond (zero-padded to six digits).
     * - `{ns}`: Nanosecond (zero-padded to nine digits).
     * - `{AM/PM}`: AM or PM (uppercase).
     * - `{am/pm}`: am or pm (lowercase).
     *
     * The specifiers follow certain conventions:
     *
     * - If a component may be formatted in multiple ways, we use shorter specifiers for ISO 8601. Specifiers for
     *   other formats have a prefix (same value with different padding, see below) or suffix (other differences).
     * - By default, value are zero-padded, where applicable.
     * - A leading underscore (`_`) means the value is space-padded.
     * - A leading caret (`^`) means the value has no padding (think of the caret in regular expressions).
     *
     * @param format The format to use.
     *
     * @result cell The parsed time.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["12:34", "12:34:56", "12:34:56.789", "abc", null]);
     *     out column.transform((cell) -> cell.str.toTime());
     *     out column.transform((cell) -> cell.str.toTime(format="{h}:{m}"));
     * }
     */
    @Pure
    @PythonName("to_time")
    fun toTime(
        format: String? = "iso"
    ) -> cell: Cell<Time?>

    /**
     * Convert the string to uppercase.
     *
     * @result cell The uppercase string.
     *
     * @example
     * pipeline example {
     *     val column = Column("a", ["ab", "bc", null]);
     *     out column.transform((cell) -> cell.str.toUppercase());
     * }
     */
    @Pure
    @PythonName("to_uppercase")
    fun toUppercase() -> cell: Cell<String?>
}

contains

Check if the string contains the substring.

Parameters:

Name Type Description Default
substring union<String, Cell<Any?>?> The substring to search for. -

Results:

Name Type Description
contains Cell<Boolean?> Whether the string contains the substring.

Examples:

pipeline example {
    val column = Column("a", ["ab", "cd", null]);
    out column.transform((cell) -> cell.str.contains("b"));
}
Stub code in StringOperations.sdsstub

@Pure
fun contains(
    substring: ConvertibleToStringCell
) -> contains: Cell<Boolean?>

endsWith

Check if the string ends with the suffix.

Parameters:

Name Type Description Default
suffix union<String, Cell<Any?>?> The expected suffix. -

Results:

Name Type Description
cell Cell<Boolean?> Whether the string ends with the suffix.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.endsWith("b"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("ends_with")
fun endsWith(
    suffix: ConvertibleToStringCell
) -> cell: Cell<Boolean?>

indexOf

Get the index of the first occurrence of the substring.

Parameters:

Name Type Description Default
substring union<String, Cell<Any?>?> The substring to search for. -

Results:

Name Type Description
cell Cell<Int?> The index of the first occurrence of the substring. If the substring is not found, null is returned.

Examples:

pipeline example {
    val column = Column("a", ["ab", "cd", null]);
    out column.transform((cell) -> cell.str.indexOf("b"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("index_of")
fun indexOf(
    substring: ConvertibleToStringCell
) -> cell: Cell<Int?>

length

Get the number of characters.

Parameters:

Name Type Description Default
optimizeForAscii Boolean Greatly speed up this operation if the string is ASCII-only. If the string contains non-ASCII characters, this option will return incorrect results, though. false

Results:

Name Type Description
cell Cell<Int?> The number of characters.

Examples:

pipeline example {
    val column = Column("a", ["", "a", "abc", null]);
    out column.transform((cell) -> cell.str.length());
}
Stub code in StringOperations.sdsstub

@Pure
fun length(
    @PythonName("optimize_for_ascii") optimizeForAscii: Boolean = false
) -> cell: Cell<Int?>

padEnd

Pad the end of the string with the given character until it has the given length.

Parameters:

Name Type Description Default
length Int The minimum length of the string. If the string is already at least as long, it is returned unchanged. Must be greater than or equal to 0. -
character String How to pad the string. Must be a single character. " "

Results:

Name Type Description
cell Cell<String?> The padded string.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bcde", null]);
    out column.transform((cell) -> cell.str.padEnd(3));
    out column.transform((cell) -> cell.str.padEnd(3, character="~"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("pad_end")
fun padEnd(
    const length: Int,
    character: String = " "
) -> cell: Cell<String?> where {
    length >= 0
}

padStart

Pad the start of the string with the given character until it has the given length.

Parameters:

Name Type Description Default
length Int The minimum length of the string. If the string is already at least as long, it is returned unchanged. Must be greater than or equal to 0. -
character String How to pad the string. Must be a single character. " "

Results:

Name Type Description
cell Cell<String?> The padded string.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bcde", null]);
    out column.transform((cell) -> cell.str.padStart(3));
    out column.transform((cell) -> cell.str.padStart(3, character="~"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("pad_start")
fun padStart(
    const length: Int,
    character: String = " "
) -> cell: Cell<String?> where {
    length >= 0
}

removePrefix

Remove a prefix from the string. Strings without the prefix are not changed.

Parameters:

Name Type Description Default
prefix union<String, Cell<Any?>?> The prefix to remove. -

Results:

Name Type Description
cell Cell<String?> The string without the prefix.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.removePrefix("a"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("remove_prefix")
fun removePrefix(
    prefix: ConvertibleToStringCell
) -> cell: Cell<String?>

removeSuffix

Remove a suffix from the string. Strings without the suffix are not changed.

Parameters:

Name Type Description Default
suffix union<String, Cell<Any?>?> The suffix to remove. -

Results:

Name Type Description
cell Cell<String?> The string without the suffix.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.removeSuffix("b"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("remove_suffix")
fun removeSuffix(
    suffix: ConvertibleToStringCell
) -> cell: Cell<String?>

repeat

Repeat the string a number of times.

Parameters:

Name Type Description Default
count union<Int, Cell<Any?>?> The number of times to repeat the string. Must be greater than or equal to 0. -

Results:

Name Type Description
cell Cell<String?> The repeated string.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.repeat(2));
}
Stub code in StringOperations.sdsstub

@Pure
fun repeat(
    count: ConvertibleToIntCell
) -> cell: Cell<String?>

replaceAll

Replace all occurrences of the old substring with the new substring.

Parameters:

Name Type Description Default
old union<String, Cell<Any?>?> The substring to replace. -
new union<String, Cell<Any?>?> The substring to replace with. -

Results:

Name Type Description
cell Cell<String?> The string with all occurrences replaced.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.replaceAll("b", "z"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("replace_all")
fun replaceAll(
    old: ConvertibleToStringCell,
    new: ConvertibleToStringCell
) -> cell: Cell<String?>

reverse

Reverse the string.

Results:

Name Type Description
cell Cell<String?> The reversed string.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.reverse());
}
Stub code in StringOperations.sdsstub

@Pure
fun reverse() -> cell: Cell<String?>

slice

Get a slice of the string.

Parameters:

Name Type Description Default
start union<Int, Cell<Any?>?> The start index of the slice. Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at -1). 0
length union<Int, Cell<Any?>?> The length of the slice. If None, the slice contains all characters starting from start. Must greater than or equal to 0. null

Results:

Name Type Description
cell Cell<String?> The sliced string.

Examples:

pipeline example {
    val column = Column("a", ["abc", "de", null]);
    out column.transform((cell) -> cell.str.slice(start = 1));
    out column.transform((cell) -> cell.str.slice(start = 1, length = 1));
}
Stub code in StringOperations.sdsstub

@Pure
fun slice(
    start: ConvertibleToIntCell = 0,
    length: ConvertibleToIntCell = null
) -> cell: Cell<String?>

startsWith

Check if the string starts with the prefix.

Parameters:

Name Type Description Default
prefix union<String, Cell<Any?>?> The expected prefix. -

Results:

Name Type Description
cell Cell<Boolean?> Whether the string starts with the prefix.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.startsWith("a"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("starts_with")
fun startsWith(
    prefix: ConvertibleToStringCell
) -> cell: Cell<Boolean?>

strip

Remove leading and trailing characters.

Parameters:

Name Type Description Default
characters union<String, Cell<Any?>?> The characters to remove. If None, whitespace is removed. null

Results:

Name Type Description
cell Cell<String?> The stripped string.

Examples:

pipeline example {
    val column = Column("a", ["  ab  ", "~ bc ~", null]);
    out column.transform((cell) -> cell.str.strip());
    out column.transform((cell) -> cell.str.strip(characters=" ~"));
}
Stub code in StringOperations.sdsstub

@Pure
fun strip(
    characters: ConvertibleToStringCell = null
) -> cell: Cell<String?>

stripEnd

Remove trailing characters.

Parameters:

Name Type Description Default
characters union<String, Cell<Any?>?> The characters to remove. If None, whitespace is removed. null

Results:

Name Type Description
cell Cell<String?> The stripped string.

Examples:

pipeline example {
    val column = Column("a", ["  ab  ", "~ bc ~", null]);
    out column.transform((cell) -> cell.str.stripEnd());
    out column.transform((cell) -> cell.str.stripEnd(characters=" ~"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("strip_end")
fun stripEnd(
    characters: ConvertibleToStringCell = null
) -> cell: Cell<String?>

stripStart

Remove leading characters.

Parameters:

Name Type Description Default
characters union<String, Cell<Any?>?> The characters to remove. If None, whitespace is removed. null

Results:

Name Type Description
cell Cell<String?> The stripped string.

Examples:

pipeline example {
    val column = Column("a", ["  ab  ", "~ bc ~", null]);
    out column.transform((cell) -> cell.str.stripStart());
    out column.transform((cell) -> cell.str.stripStart(characters=" ~"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("strip_start")
fun stripStart(
    characters: ConvertibleToStringCell = null
) -> cell: Cell<String?>

toDate

Convert a string to a date.

The format parameter controls the presentation. It can be "iso" to target ISO 8601 or a custom string. The custom string can contain fixed specifiers (see below), which are replaced with the corresponding values. The specifiers are case-sensitive and always enclosed in curly braces. Other text is included in the output verbatim. To include a literal opening curly brace, use \{, and to include a literal backslash, use \\.

The following specifiers are available:

  • {Y}, {_Y}, {^Y}: Year (zero-padded to four digits, space-padded to four digits, no padding).
  • {Y99}, {_Y99}, {^Y99}: Year modulo 100 (zero-padded to two digits, space-padded to two digits, no padding).
  • {M}, {_M}, {^M}: Month (zero-padded to two digits, space-padded to two digits, no padding).
  • {M-full}: Full name of the month (e.g. "January").
  • {M-short}: Abbreviated name of the month with three letters (e.g. "Jan").
  • {W}, {_W}, {^W}: Week number as defined by ISO 8601 (zero-padded to two digits, space-padded to two digits, no padding).
  • {D}, {_D}, {^D}: Day of the month (zero-padded to two digits, space-padded to two digits, no padding).
  • {DOW}: Day of the week as defined by ISO 8601 (1 = Monday, 7 = Sunday).
  • {DOW-full}: Full name of the day of the week (e.g. "Monday").
  • {DOW-short}: Abbreviated name of the day of the week with three letters (e.g. "Mon").
  • {DOY}, {_DOY}, {^DOY}: Day of the year, ranging from 1 to 366 (zero-padded to three digits, space-padded to three digits, no padding).

The specifiers follow certain conventions:

  • If a component may be formatted in multiple ways, we use shorter specifiers for ISO 8601. Specifiers for other formats have a prefix (same value with different padding, see below) or suffix (other differences).
  • By default, value are zero-padded, where applicable.
  • A leading underscore (_) means the value is space-padded.
  • A leading caret (^) means the value has no padding (think of the caret in regular expressions).

Parameters:

Name Type Description Default
format String? The format to use. "iso"

Results:

Name Type Description
cell Cell<Date?> The parsed date.

Examples:

pipeline example {
    val column = Column("a", ["1999-02-03", "03.02.2001", "abc", null]);
    out column.transform((cell) -> cell.str.toDate());
    out column.transform((cell) -> cell.str.toDate(format="{D}.{M}.{Y}"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("to_date")
fun toDate(
    format: String? = "iso"
) -> cell: Cell<Date?>

toDatetime

Convert a string to a datetime.

The format parameter controls the presentation. It can be "iso" to target ISO 8601 or a custom string. The custom string can contain fixed specifiers (see below), which are replaced with the corresponding values. The specifiers are case-sensitive and always enclosed in curly braces. Other text is included in the output verbatim. To include a literal opening curly brace, use \{, and to include a literal backslash, use \\.

The following specifiers for date components are available for datetime and date:

  • {Y}, {_Y}, {^Y}: Year (zero-padded to four digits, space-padded to four digits, no padding).
  • {Y99}, {_Y99}, {^Y99}: Year modulo 100 (zero-padded to two digits, space-padded to two digits, no padding).
  • {M}, {_M}, {^M}: Month (zero-padded to two digits, space-padded to two digits, no padding).
  • {M-full}: Full name of the month (e.g. "January").
  • {M-short}: Abbreviated name of the month with three letters (e.g. "Jan").
  • {W}, {_W}, {^W}: Week number as defined by ISO 8601 (zero-padded to two digits, space-padded to two digits, no padding).
  • {D}, {_D}, {^D}: Day of the month (zero-padded to two digits, space-padded to two digits, no padding).
  • {DOW}: Day of the week as defined by ISO 8601 (1 = Monday, 7 = Sunday).
  • {DOW-full}: Full name of the day of the week (e.g. "Monday").
  • {DOW-short}: Abbreviated name of the day of the week with three letters (e.g. "Mon").
  • {DOY}, {_DOY}, {^DOY}: Day of the year, ranging from 1 to 366 (zero-padded to three digits, space-padded to three digits, no padding).

The following specifiers for time components are available for datetime and time:

  • {h}, {_h}, {^h}: Hour (zero-padded to two digits, space-padded to two digits, no padding).
  • {h12}, {_h12}, {^h12}: Hour in 12-hour format (zero-padded to two digits, space-padded to two digits, no padding).
  • {m}, {_m}, {^m}: Minute (zero-padded to two digits, space-padded to two digits, no padding).
  • {s}, {_s}, {^s}: Second (zero-padded to two digits, space-padded to two digits, no padding).
  • {.f}: Fractional seconds with a leading decimal point.
  • {ms}: Millisecond (zero-padded to three digits).
  • {us}: Microsecond (zero-padded to six digits).
  • {ns}: Nanosecond (zero-padded to nine digits).
  • {AM/PM}: AM or PM (uppercase).
  • {am/pm}: am or pm (lowercase).

The following specifiers are available for datetime only:

  • {z}: Offset of the timezone from UTC without a colon (e.g. "+0000").
  • {:z}: Offset of the timezone from UTC with a colon (e.g. "+00:00").
  • {u}: The UNIX timestamp in seconds.

The specifiers follow certain conventions:

  • Generally, date components use uppercase letters and time components use lowercase letters.
  • If a component may be formatted in multiple ways, we use shorter specifiers for ISO 8601. Specifiers for other formats have a prefix (same value with different padding, see below) or suffix (other differences).
  • By default, value are zero-padded, where applicable.
  • A leading underscore (_) means the value is space-padded.
  • A leading caret (^) means the value has no padding (think of the caret in regular expressions).

Parameters:

Name Type Description Default
format String? The format to use. "iso"

Results:

Name Type Description
cell Cell<Datetime?> The parsed datetime.

Examples:

pipeline example {
    val column = Column("a", ["1999-12-31T01:02:03Z", "12:30 Jan 23 2024", "abc", null]);
    out column.transform((cell) -> cell.str.toDatetime());
    out column.transform((cell) -> cell.str.toDatetime(
        format="{h}:{m} {M-short} {D} {Y}"
    ));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("to_datetime")
fun toDatetime(
    format: String? = "iso"
) -> cell: Cell<Datetime?>

toFloat

Convert the string to a float.

Results:

Name Type Description
cell Cell<Float?> The float value. If the string cannot be converted to a float, null is returned.

Examples:

pipeline example {
    val column = Column("a", ["1", "1.5", "abc", null]);
    out column.transform((cell) -> cell.str.toFloat());
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("to_float")
fun toFloat() -> cell: Cell<Float?>

toInt

Convert the string to an integer.

Parameters:

Name Type Description Default
base union<Int, Cell<Any?>?> The base of the integer. 10

Results:

Name Type Description
cell Cell<Int?> The integer value. If the string cannot be converted to an integer, null is returned.

Examples:

pipeline example {
    val column1 = Column("a", ["1", "10", "abc", null]);
    out column1.transform((cell) -> cell.str.toInt());
}
pipeline example {
    val column2 = Column("a", ["1", "10", "abc", null]);
    out column2.transform((cell) -> cell.str.toInt(base = 2));
}

Stub code in StringOperations.sdsstub

@Pure
@PythonName("to_int")
fun toInt(
    base: ConvertibleToIntCell = 10
) -> cell: Cell<Int?>

toLowercase

Convert the string to lowercase.

Results:

Name Type Description
cell Cell<String?> The lowercase string.

Examples:

pipeline example {
    val column = Column("a", ["AB", "BC", null]);
    out column.transform((cell) -> cell.str.toLowercase());
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("to_lowercase")
fun toLowercase() -> cell: Cell<String?>

toTime

Convert a string to a time.

The format parameter controls the presentation. It can be "iso" to target ISO 8601 or a custom string. The custom string can contain fixed specifiers (see below), which are replaced with the corresponding values. The specifiers are case-sensitive and always enclosed in curly braces. Other text is included in the output verbatim. To include a literal opening curly brace, use \{, and to include a literal backslash, use \\.

The following specifiers are available:

  • {h}, {_h}, {^h}: Hour (zero-padded to two digits, space-padded to two digits, no padding).
  • {h12}, {_h12}, {^h12}: Hour in 12-hour format (zero-padded to two digits, space-padded to two digits, no padding).
  • {m}, {_m}, {^m}: Minute (zero-padded to two digits, space-padded to two digits, no padding).
  • {s}, {_s}, {^s}: Second (zero-padded to two digits, space-padded to two digits, no padding).
  • {.f}: Fractional seconds with a leading decimal point.
  • {ms}: Millisecond (zero-padded to three digits).
  • {us}: Microsecond (zero-padded to six digits).
  • {ns}: Nanosecond (zero-padded to nine digits).
  • {AM/PM}: AM or PM (uppercase).
  • {am/pm}: am or pm (lowercase).

The specifiers follow certain conventions:

  • If a component may be formatted in multiple ways, we use shorter specifiers for ISO 8601. Specifiers for other formats have a prefix (same value with different padding, see below) or suffix (other differences).
  • By default, value are zero-padded, where applicable.
  • A leading underscore (_) means the value is space-padded.
  • A leading caret (^) means the value has no padding (think of the caret in regular expressions).

Parameters:

Name Type Description Default
format String? The format to use. "iso"

Results:

Name Type Description
cell Cell<Time?> The parsed time.

Examples:

pipeline example {
    val column = Column("a", ["12:34", "12:34:56", "12:34:56.789", "abc", null]);
    out column.transform((cell) -> cell.str.toTime());
    out column.transform((cell) -> cell.str.toTime(format="{h}:{m}"));
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("to_time")
fun toTime(
    format: String? = "iso"
) -> cell: Cell<Time?>

toUppercase

Convert the string to uppercase.

Results:

Name Type Description
cell Cell<String?> The uppercase string.

Examples:

pipeline example {
    val column = Column("a", ["ab", "bc", null]);
    out column.transform((cell) -> cell.str.toUppercase());
}
Stub code in StringOperations.sdsstub

@Pure
@PythonName("to_uppercase")
fun toUppercase() -> cell: Cell<String?>