# Strings
{id: strings}

## Strings intro
{id: strings-intro}

* [String](https://crystal-lang.org/api/String.html)

![](examples/strings/strings.cr)

## Length or size of a string
{id: strings-length}
{i: size}
{i: length}

![](examples/strings/length.cr)

## Locate substring (index, rindex)
{id: strings-index}
{i: index}
{i: rindex}

![](examples/strings/index.cr)


## Reverse a string
{id: strings-revers}
{i: reverse}

* The original string stays intact

![](examples/strings/reverse.cr)

## Substring, range of characters
{id: substring}

![](examples/strings/substring.cr)
![](examples/strings/substring.out)

## String includes another string
{id: strings-includes-another-string}
{i: includes?}

![](examples/strings/includes.cr)


## String starts with
{id: strings-starts-with}
{i: starts_with}

![](examples/strings/starts_with.cr)

## String ends with
{id: strings-ends-with}
{i: ends_with}

![](examples/strings/ends_with.cr)


## Replace part of a string (substitute)
{id: strings-substitute}
{i: sub}

* If there is nothing to replace, nothing happens
* Only replaces the first occurrence of the string

![](examples/strings/substitute.cr)
![](examples/strings/substitute.out)

## Is the string empty or blank?
{id: strings-empty}
{i: size}
{i: empty?}
{i: blank?}

![](examples/strings/empty_strings.cr)

## Iterate over characters of a string
{id: strings-iterator}
{i: each_char}

![](examples/strings/string_iterator.cr)


## Type conversion  from string to float, to int
{id: type-conversion}
{i: to_f}
{i: to_i}

![](examples/strings/type_conversion.cr)

## Converting string to integer or float
{id: converting-string-to-integer-or-float}
{i: to_i}
{i: to_i?}
{i: to_f}
{i: to_f?}

![](examples/strings/convertable.cr)
![](examples/strings/convertable.out)

## Split String
{id: split-string}
{i: split}

![](examples/strings/split_string.cr)

## String Transliteration
{id: string-transliteration}
{i: tr}

![](examples/strings/tr.cr)
![](examples/strings/tr.out)

## String Builder
{id: string-builder}

![](examples/strings/build.cr)

## sprintf and %
{id: string-sprintf}

![](examples/strings/sprintf.cr)
![](examples/strings/sprintf.out)

## Split to the same string length
{id: split-to-fixed-width}

![](examples/strings/splitup.cr)

## Split characters
{id: split-characters}
{i: split}
{i: chars}

![](examples/strings/split_characters.cr)
![](examples/strings/split_characters.out)

## printf
{id: printf}
{i: printf}

![](examples/strings/printf.cr)
![](examples/strings/printf.out)

## Here documents
{id: here-documents}
{i: <<-}

![](examples/strings/here_document.cr)

