Skip to content

StringOperations

Bases: ABC

Namespace for operations on strings.

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

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", "cd"])
>>> column.transform(lambda cell: cell.str.to_uppercase())
+-----+
| a   |
| --- |
| str |
+=====+
| AB  |
| BC  |
| CD  |
+-----+

Methods:

Name Description
contains

Check if the string contains the substring.

ends_with

Check if the string ends with the suffix.

index_of

Get the index of the first occurrence of the substring.

length

Get the number of characters.

pad_end

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

pad_start

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

remove_prefix

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

remove_suffix

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

repeat

Repeat the string a number of times.

replace_all

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

reverse

Reverse the string.

slice

Get a slice of the string.

starts_with

Check if the string starts with the prefix.

strip

Remove leading and trailing characters.

strip_end

Remove trailing characters.

strip_start

Remove leading characters.

to_date

Convert a string to a date.

to_datetime

Convert a string to a datetime.

to_float

Convert the string to a float.

to_int

Convert the string to an integer.

to_lowercase

Convert the string to lowercase.

to_time

Convert a string to a time.

to_uppercase

Convert the string to uppercase.

Source code in src/safeds/data/tabular/query/_string_operations.py
  14
  15
  16
  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
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
class StringOperations(ABC):
    """
    Namespace for operations on strings.

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

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", "cd"])
    >>> column.transform(lambda cell: cell.str.to_uppercase())
    +-----+
    | a   |
    | --- |
    | str |
    +=====+
    | AB  |
    | BC  |
    | CD  |
    +-----+
    """

    # ------------------------------------------------------------------------------------------------------------------
    # Dunder methods
    # ------------------------------------------------------------------------------------------------------------------

    @abstractmethod
    def __eq__(self, other: object) -> bool: ...

    @abstractmethod
    def __hash__(self) -> int: ...

    @abstractmethod
    def __repr__(self) -> str: ...

    @abstractmethod
    def __sizeof__(self) -> int: ...

    @abstractmethod
    def __str__(self) -> str: ...

    # ------------------------------------------------------------------------------------------------------------------
    # String operations
    # ------------------------------------------------------------------------------------------------------------------

    @abstractmethod
    def contains(self, substring: _ConvertibleToStringCell) -> Cell[bool | None]:
        """
        Check if the string contains the substring.

        Parameters
        ----------
        substring:
            The substring to search for.

        Returns
        -------
        contains:
            Whether the string contains the substring.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "cd", None])
        >>> column.transform(lambda cell: cell.str.contains("b"))
        +-------+
        | a     |
        | ---   |
        | bool  |
        +=======+
        | true  |
        | false |
        | null  |
        +-------+
        """

    @abstractmethod
    def ends_with(self, suffix: _ConvertibleToStringCell) -> Cell[bool | None]:
        """
        Check if the string ends with the suffix.

        Parameters
        ----------
        suffix:
            The expected suffix.

        Returns
        -------
        cell:
            Whether the string ends with the suffix.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.ends_with("b"))
        +-------+
        | a     |
        | ---   |
        | bool  |
        +=======+
        | true  |
        | false |
        | null  |
        +-------+
        """

    @abstractmethod
    def index_of(self, substring: _ConvertibleToStringCell) -> Cell[int | None]:
        """
        Get the index of the first occurrence of the substring.

        Parameters
        ----------
        substring:
            The substring to search for.

        Returns
        -------
        cell:
            The index of the first occurrence of the substring. If the substring is not found, None is returned.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "cd", None])
        >>> column.transform(lambda cell: cell.str.index_of("b"))
        +------+
        |    a |
        |  --- |
        |  u32 |
        +======+
        |    1 |
        | null |
        | null |
        +------+
        """

    @abstractmethod
    def length(self, *, optimize_for_ascii: bool = False) -> Cell[int | None]:
        """
        Get the number of characters.

        Parameters
        ----------
        optimize_for_ascii:
            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.

        Returns
        -------
        cell:
            The number of characters.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["", "a", "abc", None])
        >>> column.transform(lambda cell: cell.str.length())
        +------+
        |    a |
        |  --- |
        |  u32 |
        +======+
        |    0 |
        |    1 |
        |    3 |
        | null |
        +------+
        """

    @abstractmethod
    def pad_end(self, length: int, *, character: str = " ") -> Cell[str | None]:
        """
        Pad the end of the string with the given character until it has the given length.

        Parameters
        ----------
        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.
        character:
            How to pad the string. Must be a single character.

        Returns
        -------
        cell:
            The padded string.

        Raises
        ------
        OutOfBoundsError
            If `length` is less than 0.
        ValueError
            If `char` is not a single character.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bcde", None])
        >>> column.transform(lambda cell: cell.str.pad_end(3))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | ab   |
        | bcde |
        | null |
        +------+

        >>> column.transform(lambda cell: cell.str.pad_end(3, character="~"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | ab~  |
        | bcde |
        | null |
        +------+
        """

    @abstractmethod
    def pad_start(self, length: int, *, character: str = " ") -> Cell[str | None]:
        """
        Pad the start of the string with the given character until it has the given length.

        Parameters
        ----------
        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.
        character:
            How to pad the string. Must be a single character.

        Returns
        -------
        cell:
            The padded string.

        Raises
        ------
        OutOfBoundsError
            If `length` is less than 0.
        ValueError
            If `char` is not a single character.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bcde", None])
        >>> column.transform(lambda cell: cell.str.pad_start(3))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        |  ab  |
        | bcde |
        | null |
        +------+

        >>> column.transform(lambda cell: cell.str.pad_start(3, character="~"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | ~ab  |
        | bcde |
        | null |
        +------+
        """

    @abstractmethod
    def remove_prefix(self, prefix: _ConvertibleToStringCell) -> Cell[str | None]:
        """
        Remove a prefix from the string. Strings without the prefix are not changed.

        Parameters
        ----------
        prefix:
            The prefix to remove.

        Returns
        -------
        cell:
            The string without the prefix.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.remove_prefix("a"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | b    |
        | bc   |
        | null |
        +------+
        """

    @abstractmethod
    def remove_suffix(self, suffix: _ConvertibleToStringCell) -> Cell[str | None]:
        """
        Remove a suffix from the string. Strings without the suffix are not changed.

        Parameters
        ----------
        suffix:
            The suffix to remove.

        Returns
        -------
        cell:
            The string without the suffix.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.remove_suffix("b"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | a    |
        | bc   |
        | null |
        +------+
        """

    @abstractmethod
    def repeat(self, count: _ConvertibleToIntCell) -> Cell[str | None]:
        """
        Repeat the string a number of times.

        Parameters
        ----------
        count:
            The number of times to repeat the string. Must be greater than or equal to 0.

        Returns
        -------
        cell:
            The repeated string.

        Raises
        ------
        OutOfBoundsError
            If `count` is less than 0.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.repeat(2))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | abab |
        | bcbc |
        | null |
        +------+
        """

    @abstractmethod
    def replace_all(self, old: _ConvertibleToStringCell, new: _ConvertibleToStringCell) -> Cell[str | None]:
        """
        Replace all occurrences of the old substring with the new substring.

        Parameters
        ----------
        old:
            The substring to replace.
        new:
            The substring to replace with.

        Returns
        -------
        cell:
            The string with all occurrences replaced.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.replace_all("b", "z"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | az   |
        | zc   |
        | null |
        +------+
        """

    @abstractmethod
    def reverse(self) -> Cell[str | None]:
        """
        Reverse the string.

        Returns
        -------
        cell:
            The reversed string.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.reverse())
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | ba   |
        | cb   |
        | null |
        +------+
        """

    @abstractmethod
    def slice(
        self,
        *,
        start: _ConvertibleToIntCell = 0,
        length: _ConvertibleToIntCell = None,
    ) -> Cell[str | None]:
        """
        Get a slice of the string.

        Parameters
        ----------
        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).
        length:
            The length of the slice. If None, the slice contains all characters starting from `start`. Must greater than
            or equal to 0.

        Returns
        -------
        cell:
            The sliced string.

        Raises
        ------
        OutOfBoundsError
            If `length` is less than 0.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["abc", "de", None])
        >>> column.transform(lambda cell: cell.str.slice(start=1))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | bc   |
        | e    |
        | null |
        +------+

        >>> column.transform(lambda cell: cell.str.slice(start=1, length=1))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | b    |
        | e    |
        | null |
        +------+
        """

    @abstractmethod
    def starts_with(self, prefix: _ConvertibleToStringCell) -> Cell[bool | None]:
        """
        Check if the string starts with the prefix.

        Parameters
        ----------
        prefix:
            The expected prefix.

        Returns
        -------
        cell:
            Whether the string starts with the prefix.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.starts_with("a"))
        +-------+
        | a     |
        | ---   |
        | bool  |
        +=======+
        | true  |
        | false |
        | null  |
        +-------+
        """

    @abstractmethod
    def strip(self, *, characters: _ConvertibleToStringCell = None) -> Cell[str | None]:
        """
        Remove leading and trailing characters.

        Parameters
        ----------
        characters:
            The characters to remove. If None, whitespace is removed.

        Returns
        -------
        cell:
            The stripped string.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["  ab  ", "~ bc ~", None])
        >>> column.transform(lambda cell: cell.str.strip())
        +--------+
        | a      |
        | ---    |
        | str    |
        +========+
        | ab     |
        | ~ bc ~ |
        | null   |
        +--------+

        >>> column.transform(lambda cell: cell.str.strip(characters=" ~"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | ab   |
        | bc   |
        | null |
        +------+
        """

    @abstractmethod
    def strip_end(self, *, characters: _ConvertibleToStringCell = None) -> Cell[str | None]:
        """
        Remove trailing characters.

        Parameters
        ----------
        characters:
            The characters to remove. If None, whitespace is removed.

        Returns
        -------
        cell:
            The stripped string.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["  ab  ", "~ bc ~", None])
        >>> column.transform(lambda cell: cell.str.strip_end())
        +--------+
        | a      |
        | ---    |
        | str    |
        +========+
        |   ab   |
        | ~ bc ~ |
        | null   |
        +--------+

        >>> column.transform(lambda cell: cell.str.strip_end(characters=" ~"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        |   ab |
        | ~ bc |
        | null |
        +------+
        """

    @abstractmethod
    def strip_start(self, *, characters: _ConvertibleToStringCell = None) -> Cell[str | None]:
        """
        Remove leading characters.

        Parameters
        ----------
        characters:
            The characters to remove. If None, whitespace is removed.

        Returns
        -------
        cell:
            The stripped string.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["  ab  ", "~ bc ~", None])
        >>> column.transform(lambda cell: cell.str.strip_start())
        +--------+
        | a      |
        | ---    |
        | str    |
        +========+
        | ab     |
        | ~ bc ~ |
        | null   |
        +--------+

        >>> column.transform(lambda cell: cell.str.strip_start(characters=" ~"))
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | ab   |
        | bc ~ |
        | null |
        +------+
        """

    @abstractmethod
    def to_date(self, *, format: str | None = "iso") -> Cell[datetime.date | None]:
        r"""
        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
        ----------
        format:
            The format to use.

        Returns
        -------
        cell:
            The parsed date.

        Raises
        ------
        ValueError
            If the format is invalid.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["1999-02-03", "03.02.2001", "abc", None])
        >>> column.transform(lambda cell: cell.str.to_date())
        +------------+
        | a          |
        | ---        |
        | date       |
        +============+
        | 1999-02-03 |
        | null       |
        | null       |
        | null       |
        +------------+

        >>> column.transform(lambda cell: cell.str.to_date(format="{D}.{M}.{Y}"))
        +------------+
        | a          |
        | ---        |
        | date       |
        +============+
        | null       |
        | 2001-02-03 |
        | null       |
        | null       |
        +------------+
        """

    @abstractmethod
    def to_datetime(self, *, format: str | None = "iso") -> Cell[datetime.datetime | None]:
        r"""
        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
        ----------
        format:
            The format to use.

        Returns
        -------
        cell:
            The parsed datetime.

        Raises
        ------
        ValueError
            If the format is invalid.

        Examples
        --------
        >>> from datetime import date, datetime
        >>> from safeds.data.tabular.containers import Column
        >>> column1 = Column("a", ["1999-12-31T01:02:03Z", "12:30 Jan 23 2024", "abc", None])
        >>> column1.transform(lambda cell: cell.str.to_datetime())
        +-------------------------+
        | a                       |
        | ---                     |
        | datetime[μs, UTC]       |
        +=========================+
        | 1999-12-31 01:02:03 UTC |
        | null                    |
        | null                    |
        | null                    |
        +-------------------------+

        >>> column1.transform(lambda cell: cell.str.to_datetime(
        ...     format="{h}:{m} {M-short} {D} {Y}"
        ... ))
        +---------------------+
        | a                   |
        | ---                 |
        | datetime[μs]        |
        +=====================+
        | null                |
        | 2024-01-23 12:30:00 |
        | null                |
        | null                |
        +---------------------+
        """

    @abstractmethod
    def to_float(self) -> Cell[float | None]:
        """
        Convert the string to a float.

        Returns
        -------
        cell:
            The float value. If the string cannot be converted to a float, None is returned.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["1", "1.5", "abc", None])
        >>> column.transform(lambda cell: cell.str.to_float())
        +---------+
        |       a |
        |     --- |
        |     f64 |
        +=========+
        | 1.00000 |
        | 1.50000 |
        |    null |
        |    null |
        +---------+
        """

    @abstractmethod
    def to_int(self, *, base: _ConvertibleToIntCell = 10) -> Cell[int | None]:
        """
        Convert the string to an integer.

        Parameters
        ----------
        base:
            The base of the integer.

        Returns
        -------
        cell:
            The integer value. If the string cannot be converted to an integer, None is returned.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column1 = Column("a", ["1", "10", "abc", None])
        >>> column1.transform(lambda cell: cell.str.to_int())
        +------+
        |    a |
        |  --- |
        |  i64 |
        +======+
        |    1 |
        |   10 |
        | null |
        | null |
        +------+

        >>> column2 = Column("a", ["1", "10", "abc", None])
        >>> column2.transform(lambda cell: cell.str.to_int(base=2))
        +------+
        |    a |
        |  --- |
        |  i64 |
        +======+
        |    1 |
        |    2 |
        | null |
        | null |
        +------+
        """

    @abstractmethod
    def to_lowercase(self) -> Cell[str | None]:
        """
        Convert the string to lowercase.

        Returns
        -------
        cell:
            The lowercase string.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["AB", "BC", None])
        >>> column.transform(lambda cell: cell.str.to_lowercase())
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | ab   |
        | bc   |
        | null |
        +------+
        """

    @abstractmethod
    def to_time(self, *, format: str | None = "iso") -> Cell[datetime.time | None]:
        r"""
        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
        ----------
        format:
            The format to use.

        Returns
        -------
        cell:
            The parsed time.

        Raises
        ------
        ValueError
            If the format is invalid.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["12:34", "12:34:56", "12:34:56.789", "abc", None])
        >>> column.transform(lambda cell: cell.str.to_time())
        +--------------+
        | a            |
        | ---          |
        | time         |
        +==============+
        | null         |
        | 12:34:56     |
        | 12:34:56.789 |
        | null         |
        | null         |
        +--------------+

        >>> column.transform(lambda cell: cell.str.to_time(format="{h}:{m}"))
        +----------+
        | a        |
        | ---      |
        | time     |
        +==========+
        | 12:34:00 |
        | null     |
        | null     |
        | null     |
        | null     |
        +----------+
        """

    @abstractmethod
    def to_uppercase(self) -> Cell[str | None]:
        """
        Convert the string to uppercase.

        Returns
        -------
        cell:
            The uppercase string.

        Examples
        --------
        >>> from safeds.data.tabular.containers import Column
        >>> column = Column("a", ["ab", "bc", None])
        >>> column.transform(lambda cell: cell.str.to_uppercase())
        +------+
        | a    |
        | ---  |
        | str  |
        +======+
        | AB   |
        | BC   |
        | null |
        +------+
        """

contains

Check if the string contains the substring.

Parameters:

Name Type Description Default
substring _ConvertibleToStringCell

The substring to search for.

required

Returns:

Name Type Description
contains Cell[bool | None]

Whether the string contains the substring.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "cd", None])
>>> column.transform(lambda cell: cell.str.contains("b"))
+-------+
| a     |
| ---   |
| bool  |
+=======+
| true  |
| false |
| null  |
+-------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def contains(self, substring: _ConvertibleToStringCell) -> Cell[bool | None]:
    """
    Check if the string contains the substring.

    Parameters
    ----------
    substring:
        The substring to search for.

    Returns
    -------
    contains:
        Whether the string contains the substring.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "cd", None])
    >>> column.transform(lambda cell: cell.str.contains("b"))
    +-------+
    | a     |
    | ---   |
    | bool  |
    +=======+
    | true  |
    | false |
    | null  |
    +-------+
    """

ends_with

Check if the string ends with the suffix.

Parameters:

Name Type Description Default
suffix _ConvertibleToStringCell

The expected suffix.

required

Returns:

Name Type Description
cell Cell[bool | None]

Whether the string ends with the suffix.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.ends_with("b"))
+-------+
| a     |
| ---   |
| bool  |
+=======+
| true  |
| false |
| null  |
+-------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def ends_with(self, suffix: _ConvertibleToStringCell) -> Cell[bool | None]:
    """
    Check if the string ends with the suffix.

    Parameters
    ----------
    suffix:
        The expected suffix.

    Returns
    -------
    cell:
        Whether the string ends with the suffix.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.ends_with("b"))
    +-------+
    | a     |
    | ---   |
    | bool  |
    +=======+
    | true  |
    | false |
    | null  |
    +-------+
    """

index_of

Get the index of the first occurrence of the substring.

Parameters:

Name Type Description Default
substring _ConvertibleToStringCell

The substring to search for.

required

Returns:

Name Type Description
cell Cell[int | None]

The index of the first occurrence of the substring. If the substring is not found, None is returned.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "cd", None])
>>> column.transform(lambda cell: cell.str.index_of("b"))
+------+
|    a |
|  --- |
|  u32 |
+======+
|    1 |
| null |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def index_of(self, substring: _ConvertibleToStringCell) -> Cell[int | None]:
    """
    Get the index of the first occurrence of the substring.

    Parameters
    ----------
    substring:
        The substring to search for.

    Returns
    -------
    cell:
        The index of the first occurrence of the substring. If the substring is not found, None is returned.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "cd", None])
    >>> column.transform(lambda cell: cell.str.index_of("b"))
    +------+
    |    a |
    |  --- |
    |  u32 |
    +======+
    |    1 |
    | null |
    | null |
    +------+
    """

length

Get the number of characters.

Parameters:

Name Type Description Default
optimize_for_ascii bool

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

Returns:

Name Type Description
cell Cell[int | None]

The number of characters.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["", "a", "abc", None])
>>> column.transform(lambda cell: cell.str.length())
+------+
|    a |
|  --- |
|  u32 |
+======+
|    0 |
|    1 |
|    3 |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def length(self, *, optimize_for_ascii: bool = False) -> Cell[int | None]:
    """
    Get the number of characters.

    Parameters
    ----------
    optimize_for_ascii:
        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.

    Returns
    -------
    cell:
        The number of characters.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["", "a", "abc", None])
    >>> column.transform(lambda cell: cell.str.length())
    +------+
    |    a |
    |  --- |
    |  u32 |
    +======+
    |    0 |
    |    1 |
    |    3 |
    | null |
    +------+
    """

pad_end

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.

required
character str

How to pad the string. Must be a single character.

' '

Returns:

Name Type Description
cell Cell[str | None]

The padded string.

Raises:

Type Description
OutOfBoundsError

If length is less than 0.

ValueError

If char is not a single character.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bcde", None])
>>> column.transform(lambda cell: cell.str.pad_end(3))
+------+
| a    |
| ---  |
| str  |
+======+
| ab   |
| bcde |
| null |
+------+
>>> column.transform(lambda cell: cell.str.pad_end(3, character="~"))
+------+
| a    |
| ---  |
| str  |
+======+
| ab~  |
| bcde |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def pad_end(self, length: int, *, character: str = " ") -> Cell[str | None]:
    """
    Pad the end of the string with the given character until it has the given length.

    Parameters
    ----------
    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.
    character:
        How to pad the string. Must be a single character.

    Returns
    -------
    cell:
        The padded string.

    Raises
    ------
    OutOfBoundsError
        If `length` is less than 0.
    ValueError
        If `char` is not a single character.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bcde", None])
    >>> column.transform(lambda cell: cell.str.pad_end(3))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | ab   |
    | bcde |
    | null |
    +------+

    >>> column.transform(lambda cell: cell.str.pad_end(3, character="~"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | ab~  |
    | bcde |
    | null |
    +------+
    """

pad_start

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.

required
character str

How to pad the string. Must be a single character.

' '

Returns:

Name Type Description
cell Cell[str | None]

The padded string.

Raises:

Type Description
OutOfBoundsError

If length is less than 0.

ValueError

If char is not a single character.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bcde", None])
>>> column.transform(lambda cell: cell.str.pad_start(3))
+------+
| a    |
| ---  |
| str  |
+======+
|  ab  |
| bcde |
| null |
+------+
>>> column.transform(lambda cell: cell.str.pad_start(3, character="~"))
+------+
| a    |
| ---  |
| str  |
+======+
| ~ab  |
| bcde |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def pad_start(self, length: int, *, character: str = " ") -> Cell[str | None]:
    """
    Pad the start of the string with the given character until it has the given length.

    Parameters
    ----------
    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.
    character:
        How to pad the string. Must be a single character.

    Returns
    -------
    cell:
        The padded string.

    Raises
    ------
    OutOfBoundsError
        If `length` is less than 0.
    ValueError
        If `char` is not a single character.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bcde", None])
    >>> column.transform(lambda cell: cell.str.pad_start(3))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    |  ab  |
    | bcde |
    | null |
    +------+

    >>> column.transform(lambda cell: cell.str.pad_start(3, character="~"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | ~ab  |
    | bcde |
    | null |
    +------+
    """

remove_prefix

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

Parameters:

Name Type Description Default
prefix _ConvertibleToStringCell

The prefix to remove.

required

Returns:

Name Type Description
cell Cell[str | None]

The string without the prefix.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.remove_prefix("a"))
+------+
| a    |
| ---  |
| str  |
+======+
| b    |
| bc   |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def remove_prefix(self, prefix: _ConvertibleToStringCell) -> Cell[str | None]:
    """
    Remove a prefix from the string. Strings without the prefix are not changed.

    Parameters
    ----------
    prefix:
        The prefix to remove.

    Returns
    -------
    cell:
        The string without the prefix.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.remove_prefix("a"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | b    |
    | bc   |
    | null |
    +------+
    """

remove_suffix

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

Parameters:

Name Type Description Default
suffix _ConvertibleToStringCell

The suffix to remove.

required

Returns:

Name Type Description
cell Cell[str | None]

The string without the suffix.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.remove_suffix("b"))
+------+
| a    |
| ---  |
| str  |
+======+
| a    |
| bc   |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def remove_suffix(self, suffix: _ConvertibleToStringCell) -> Cell[str | None]:
    """
    Remove a suffix from the string. Strings without the suffix are not changed.

    Parameters
    ----------
    suffix:
        The suffix to remove.

    Returns
    -------
    cell:
        The string without the suffix.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.remove_suffix("b"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | a    |
    | bc   |
    | null |
    +------+
    """

repeat

Repeat the string a number of times.

Parameters:

Name Type Description Default
count _ConvertibleToIntCell

The number of times to repeat the string. Must be greater than or equal to 0.

required

Returns:

Name Type Description
cell Cell[str | None]

The repeated string.

Raises:

Type Description
OutOfBoundsError

If count is less than 0.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.repeat(2))
+------+
| a    |
| ---  |
| str  |
+======+
| abab |
| bcbc |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def repeat(self, count: _ConvertibleToIntCell) -> Cell[str | None]:
    """
    Repeat the string a number of times.

    Parameters
    ----------
    count:
        The number of times to repeat the string. Must be greater than or equal to 0.

    Returns
    -------
    cell:
        The repeated string.

    Raises
    ------
    OutOfBoundsError
        If `count` is less than 0.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.repeat(2))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | abab |
    | bcbc |
    | null |
    +------+
    """

replace_all

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

Parameters:

Name Type Description Default
old _ConvertibleToStringCell

The substring to replace.

required
new _ConvertibleToStringCell

The substring to replace with.

required

Returns:

Name Type Description
cell Cell[str | None]

The string with all occurrences replaced.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.replace_all("b", "z"))
+------+
| a    |
| ---  |
| str  |
+======+
| az   |
| zc   |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def replace_all(self, old: _ConvertibleToStringCell, new: _ConvertibleToStringCell) -> Cell[str | None]:
    """
    Replace all occurrences of the old substring with the new substring.

    Parameters
    ----------
    old:
        The substring to replace.
    new:
        The substring to replace with.

    Returns
    -------
    cell:
        The string with all occurrences replaced.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.replace_all("b", "z"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | az   |
    | zc   |
    | null |
    +------+
    """

reverse

Reverse the string.

Returns:

Name Type Description
cell Cell[str | None]

The reversed string.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.reverse())
+------+
| a    |
| ---  |
| str  |
+======+
| ba   |
| cb   |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def reverse(self) -> Cell[str | None]:
    """
    Reverse the string.

    Returns
    -------
    cell:
        The reversed string.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.reverse())
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | ba   |
    | cb   |
    | null |
    +------+
    """

slice

Get a slice of the string.

Parameters:

Name Type Description Default
start _ConvertibleToIntCell

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 _ConvertibleToIntCell

The length of the slice. If None, the slice contains all characters starting from start. Must greater than or equal to 0.

None

Returns:

Name Type Description
cell Cell[str | None]

The sliced string.

Raises:

Type Description
OutOfBoundsError

If length is less than 0.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["abc", "de", None])
>>> column.transform(lambda cell: cell.str.slice(start=1))
+------+
| a    |
| ---  |
| str  |
+======+
| bc   |
| e    |
| null |
+------+
>>> column.transform(lambda cell: cell.str.slice(start=1, length=1))
+------+
| a    |
| ---  |
| str  |
+======+
| b    |
| e    |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def slice(
    self,
    *,
    start: _ConvertibleToIntCell = 0,
    length: _ConvertibleToIntCell = None,
) -> Cell[str | None]:
    """
    Get a slice of the string.

    Parameters
    ----------
    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).
    length:
        The length of the slice. If None, the slice contains all characters starting from `start`. Must greater than
        or equal to 0.

    Returns
    -------
    cell:
        The sliced string.

    Raises
    ------
    OutOfBoundsError
        If `length` is less than 0.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["abc", "de", None])
    >>> column.transform(lambda cell: cell.str.slice(start=1))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | bc   |
    | e    |
    | null |
    +------+

    >>> column.transform(lambda cell: cell.str.slice(start=1, length=1))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | b    |
    | e    |
    | null |
    +------+
    """

starts_with

Check if the string starts with the prefix.

Parameters:

Name Type Description Default
prefix _ConvertibleToStringCell

The expected prefix.

required

Returns:

Name Type Description
cell Cell[bool | None]

Whether the string starts with the prefix.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.starts_with("a"))
+-------+
| a     |
| ---   |
| bool  |
+=======+
| true  |
| false |
| null  |
+-------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def starts_with(self, prefix: _ConvertibleToStringCell) -> Cell[bool | None]:
    """
    Check if the string starts with the prefix.

    Parameters
    ----------
    prefix:
        The expected prefix.

    Returns
    -------
    cell:
        Whether the string starts with the prefix.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.starts_with("a"))
    +-------+
    | a     |
    | ---   |
    | bool  |
    +=======+
    | true  |
    | false |
    | null  |
    +-------+
    """

strip

Remove leading and trailing characters.

Parameters:

Name Type Description Default
characters _ConvertibleToStringCell

The characters to remove. If None, whitespace is removed.

None

Returns:

Name Type Description
cell Cell[str | None]

The stripped string.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["  ab  ", "~ bc ~", None])
>>> column.transform(lambda cell: cell.str.strip())
+--------+
| a      |
| ---    |
| str    |
+========+
| ab     |
| ~ bc ~ |
| null   |
+--------+
>>> column.transform(lambda cell: cell.str.strip(characters=" ~"))
+------+
| a    |
| ---  |
| str  |
+======+
| ab   |
| bc   |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def strip(self, *, characters: _ConvertibleToStringCell = None) -> Cell[str | None]:
    """
    Remove leading and trailing characters.

    Parameters
    ----------
    characters:
        The characters to remove. If None, whitespace is removed.

    Returns
    -------
    cell:
        The stripped string.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["  ab  ", "~ bc ~", None])
    >>> column.transform(lambda cell: cell.str.strip())
    +--------+
    | a      |
    | ---    |
    | str    |
    +========+
    | ab     |
    | ~ bc ~ |
    | null   |
    +--------+

    >>> column.transform(lambda cell: cell.str.strip(characters=" ~"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | ab   |
    | bc   |
    | null |
    +------+
    """

strip_end

Remove trailing characters.

Parameters:

Name Type Description Default
characters _ConvertibleToStringCell

The characters to remove. If None, whitespace is removed.

None

Returns:

Name Type Description
cell Cell[str | None]

The stripped string.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["  ab  ", "~ bc ~", None])
>>> column.transform(lambda cell: cell.str.strip_end())
+--------+
| a      |
| ---    |
| str    |
+========+
|   ab   |
| ~ bc ~ |
| null   |
+--------+
>>> column.transform(lambda cell: cell.str.strip_end(characters=" ~"))
+------+
| a    |
| ---  |
| str  |
+======+
|   ab |
| ~ bc |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def strip_end(self, *, characters: _ConvertibleToStringCell = None) -> Cell[str | None]:
    """
    Remove trailing characters.

    Parameters
    ----------
    characters:
        The characters to remove. If None, whitespace is removed.

    Returns
    -------
    cell:
        The stripped string.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["  ab  ", "~ bc ~", None])
    >>> column.transform(lambda cell: cell.str.strip_end())
    +--------+
    | a      |
    | ---    |
    | str    |
    +========+
    |   ab   |
    | ~ bc ~ |
    | null   |
    +--------+

    >>> column.transform(lambda cell: cell.str.strip_end(characters=" ~"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    |   ab |
    | ~ bc |
    | null |
    +------+
    """

strip_start

Remove leading characters.

Parameters:

Name Type Description Default
characters _ConvertibleToStringCell

The characters to remove. If None, whitespace is removed.

None

Returns:

Name Type Description
cell Cell[str | None]

The stripped string.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["  ab  ", "~ bc ~", None])
>>> column.transform(lambda cell: cell.str.strip_start())
+--------+
| a      |
| ---    |
| str    |
+========+
| ab     |
| ~ bc ~ |
| null   |
+--------+
>>> column.transform(lambda cell: cell.str.strip_start(characters=" ~"))
+------+
| a    |
| ---  |
| str  |
+======+
| ab   |
| bc ~ |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def strip_start(self, *, characters: _ConvertibleToStringCell = None) -> Cell[str | None]:
    """
    Remove leading characters.

    Parameters
    ----------
    characters:
        The characters to remove. If None, whitespace is removed.

    Returns
    -------
    cell:
        The stripped string.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["  ab  ", "~ bc ~", None])
    >>> column.transform(lambda cell: cell.str.strip_start())
    +--------+
    | a      |
    | ---    |
    | str    |
    +========+
    | ab     |
    | ~ bc ~ |
    | null   |
    +--------+

    >>> column.transform(lambda cell: cell.str.strip_start(characters=" ~"))
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | ab   |
    | bc ~ |
    | null |
    +------+
    """

to_date

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 str | None

The format to use.

'iso'

Returns:

Name Type Description
cell Cell[date | None]

The parsed date.

Raises:

Type Description
ValueError

If the format is invalid.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["1999-02-03", "03.02.2001", "abc", None])
>>> column.transform(lambda cell: cell.str.to_date())
+------------+
| a          |
| ---        |
| date       |
+============+
| 1999-02-03 |
| null       |
| null       |
| null       |
+------------+
>>> column.transform(lambda cell: cell.str.to_date(format="{D}.{M}.{Y}"))
+------------+
| a          |
| ---        |
| date       |
+============+
| null       |
| 2001-02-03 |
| null       |
| null       |
+------------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def to_date(self, *, format: str | None = "iso") -> Cell[datetime.date | None]:
    r"""
    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
    ----------
    format:
        The format to use.

    Returns
    -------
    cell:
        The parsed date.

    Raises
    ------
    ValueError
        If the format is invalid.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["1999-02-03", "03.02.2001", "abc", None])
    >>> column.transform(lambda cell: cell.str.to_date())
    +------------+
    | a          |
    | ---        |
    | date       |
    +============+
    | 1999-02-03 |
    | null       |
    | null       |
    | null       |
    +------------+

    >>> column.transform(lambda cell: cell.str.to_date(format="{D}.{M}.{Y}"))
    +------------+
    | a          |
    | ---        |
    | date       |
    +============+
    | null       |
    | 2001-02-03 |
    | null       |
    | null       |
    +------------+
    """

to_datetime

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 str | None

The format to use.

'iso'

Returns:

Name Type Description
cell Cell[datetime | None]

The parsed datetime.

Raises:

Type Description
ValueError

If the format is invalid.

Examples:

>>> from datetime import date, datetime
>>> from safeds.data.tabular.containers import Column
>>> column1 = Column("a", ["1999-12-31T01:02:03Z", "12:30 Jan 23 2024", "abc", None])
>>> column1.transform(lambda cell: cell.str.to_datetime())
+-------------------------+
| a                       |
| ---                     |
| datetime[μs, UTC]       |
+=========================+
| 1999-12-31 01:02:03 UTC |
| null                    |
| null                    |
| null                    |
+-------------------------+
>>> column1.transform(lambda cell: cell.str.to_datetime(
...     format="{h}:{m} {M-short} {D} {Y}"
... ))
+---------------------+
| a                   |
| ---                 |
| datetime[μs]        |
+=====================+
| null                |
| 2024-01-23 12:30:00 |
| null                |
| null                |
+---------------------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def to_datetime(self, *, format: str | None = "iso") -> Cell[datetime.datetime | None]:
    r"""
    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
    ----------
    format:
        The format to use.

    Returns
    -------
    cell:
        The parsed datetime.

    Raises
    ------
    ValueError
        If the format is invalid.

    Examples
    --------
    >>> from datetime import date, datetime
    >>> from safeds.data.tabular.containers import Column
    >>> column1 = Column("a", ["1999-12-31T01:02:03Z", "12:30 Jan 23 2024", "abc", None])
    >>> column1.transform(lambda cell: cell.str.to_datetime())
    +-------------------------+
    | a                       |
    | ---                     |
    | datetime[μs, UTC]       |
    +=========================+
    | 1999-12-31 01:02:03 UTC |
    | null                    |
    | null                    |
    | null                    |
    +-------------------------+

    >>> column1.transform(lambda cell: cell.str.to_datetime(
    ...     format="{h}:{m} {M-short} {D} {Y}"
    ... ))
    +---------------------+
    | a                   |
    | ---                 |
    | datetime[μs]        |
    +=====================+
    | null                |
    | 2024-01-23 12:30:00 |
    | null                |
    | null                |
    +---------------------+
    """

to_float

Convert the string to a float.

Returns:

Name Type Description
cell Cell[float | None]

The float value. If the string cannot be converted to a float, None is returned.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["1", "1.5", "abc", None])
>>> column.transform(lambda cell: cell.str.to_float())
+---------+
|       a |
|     --- |
|     f64 |
+=========+
| 1.00000 |
| 1.50000 |
|    null |
|    null |
+---------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def to_float(self) -> Cell[float | None]:
    """
    Convert the string to a float.

    Returns
    -------
    cell:
        The float value. If the string cannot be converted to a float, None is returned.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["1", "1.5", "abc", None])
    >>> column.transform(lambda cell: cell.str.to_float())
    +---------+
    |       a |
    |     --- |
    |     f64 |
    +=========+
    | 1.00000 |
    | 1.50000 |
    |    null |
    |    null |
    +---------+
    """

to_int

Convert the string to an integer.

Parameters:

Name Type Description Default
base _ConvertibleToIntCell

The base of the integer.

10

Returns:

Name Type Description
cell Cell[int | None]

The integer value. If the string cannot be converted to an integer, None is returned.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column1 = Column("a", ["1", "10", "abc", None])
>>> column1.transform(lambda cell: cell.str.to_int())
+------+
|    a |
|  --- |
|  i64 |
+======+
|    1 |
|   10 |
| null |
| null |
+------+
>>> column2 = Column("a", ["1", "10", "abc", None])
>>> column2.transform(lambda cell: cell.str.to_int(base=2))
+------+
|    a |
|  --- |
|  i64 |
+======+
|    1 |
|    2 |
| null |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def to_int(self, *, base: _ConvertibleToIntCell = 10) -> Cell[int | None]:
    """
    Convert the string to an integer.

    Parameters
    ----------
    base:
        The base of the integer.

    Returns
    -------
    cell:
        The integer value. If the string cannot be converted to an integer, None is returned.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column1 = Column("a", ["1", "10", "abc", None])
    >>> column1.transform(lambda cell: cell.str.to_int())
    +------+
    |    a |
    |  --- |
    |  i64 |
    +======+
    |    1 |
    |   10 |
    | null |
    | null |
    +------+

    >>> column2 = Column("a", ["1", "10", "abc", None])
    >>> column2.transform(lambda cell: cell.str.to_int(base=2))
    +------+
    |    a |
    |  --- |
    |  i64 |
    +======+
    |    1 |
    |    2 |
    | null |
    | null |
    +------+
    """

to_lowercase

Convert the string to lowercase.

Returns:

Name Type Description
cell Cell[str | None]

The lowercase string.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["AB", "BC", None])
>>> column.transform(lambda cell: cell.str.to_lowercase())
+------+
| a    |
| ---  |
| str  |
+======+
| ab   |
| bc   |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def to_lowercase(self) -> Cell[str | None]:
    """
    Convert the string to lowercase.

    Returns
    -------
    cell:
        The lowercase string.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["AB", "BC", None])
    >>> column.transform(lambda cell: cell.str.to_lowercase())
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | ab   |
    | bc   |
    | null |
    +------+
    """

to_time

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 str | None

The format to use.

'iso'

Returns:

Name Type Description
cell Cell[time | None]

The parsed time.

Raises:

Type Description
ValueError

If the format is invalid.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["12:34", "12:34:56", "12:34:56.789", "abc", None])
>>> column.transform(lambda cell: cell.str.to_time())
+--------------+
| a            |
| ---          |
| time         |
+==============+
| null         |
| 12:34:56     |
| 12:34:56.789 |
| null         |
| null         |
+--------------+
>>> column.transform(lambda cell: cell.str.to_time(format="{h}:{m}"))
+----------+
| a        |
| ---      |
| time     |
+==========+
| 12:34:00 |
| null     |
| null     |
| null     |
| null     |
+----------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def to_time(self, *, format: str | None = "iso") -> Cell[datetime.time | None]:
    r"""
    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
    ----------
    format:
        The format to use.

    Returns
    -------
    cell:
        The parsed time.

    Raises
    ------
    ValueError
        If the format is invalid.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["12:34", "12:34:56", "12:34:56.789", "abc", None])
    >>> column.transform(lambda cell: cell.str.to_time())
    +--------------+
    | a            |
    | ---          |
    | time         |
    +==============+
    | null         |
    | 12:34:56     |
    | 12:34:56.789 |
    | null         |
    | null         |
    +--------------+

    >>> column.transform(lambda cell: cell.str.to_time(format="{h}:{m}"))
    +----------+
    | a        |
    | ---      |
    | time     |
    +==========+
    | 12:34:00 |
    | null     |
    | null     |
    | null     |
    | null     |
    +----------+
    """

to_uppercase

Convert the string to uppercase.

Returns:

Name Type Description
cell Cell[str | None]

The uppercase string.

Examples:

>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", ["ab", "bc", None])
>>> column.transform(lambda cell: cell.str.to_uppercase())
+------+
| a    |
| ---  |
| str  |
+======+
| AB   |
| BC   |
| null |
+------+
Source code in src/safeds/data/tabular/query/_string_operations.py
@abstractmethod
def to_uppercase(self) -> Cell[str | None]:
    """
    Convert the string to uppercase.

    Returns
    -------
    cell:
        The uppercase string.

    Examples
    --------
    >>> from safeds.data.tabular.containers import Column
    >>> column = Column("a", ["ab", "bc", None])
    >>> column.transform(lambda cell: cell.str.to_uppercase())
    +------+
    | a    |
    | ---  |
    | str  |
    +======+
    | AB   |
    | BC   |
    | null |
    +------+
    """