elixir strings
In Elixir, strings are defined using double quotes ("") or single quotes (''). Both types of quotes can be used interchangeably to define strings. Here are some examples:
string1 = "Hello, World!"
string2 = 'Hello, World!'
Elixir supports string interpolation, which allows you to embed expressions within a string. To perform string interpolation, you need to use double quotes (""):
name = "John"
age = 30
greeting = "My name is #{name} and I am #{age} years old."
You can concatenate strings using the <>
operator:
string1 = "Hello, "
string2 = "World!"
result = string1 <> string2
Elixir also provides several string manipulation functions, such as String.length/1
to get the length of a string, String.upcase/1
to convert a string to uppercase, and String.downcase/1
to convert a string to lowercase:
string = "Hello, World!"
length = String.length(string)
uppercase = String.upcase(string)
lowercase = String.downcase(string)
You can find more string manipulation functions in the Elixir documentation.