Strings and symbols¶
Engee uses strings to specify text. Strings are encodings of Unicode character code sequences. In this article, we will look at specifying characters and strings, and some basic operations for working with them.
Symbols¶
A character is specified using single brackets. And has the data type char. The character can be converted to a numeric value, which is a Unicode character code.
c = 'y'
c1 = Int(c)
typeof(c1)
Strings¶
Any sequence of characters can be stored as a string using the string data type. To create a string, enclose the text in double quotes.
str = "Hello, world"
The phrase "Hello, world" is 12 characters long and is a string scalar. You can use it to name files, graphs, or to specify other textual information.
You can determine the number of characters in a string using the function length()
.
length(str)
If the text contains inverted commas, it must be enclosed in three pairs of inverted commas.
str = """Текст в кавычках"""
To combine several characters or strings, there is a function string()
.
A = "Первая"
B = "и вторая части строки"
C = string(A, ' ', B)
You can also concatenate multiple strings using the * character.
name = "Engee"
domen = ".com"
adress = name*domen
Any type of input data can be converted to a string using the function repr()
.
str_pi = repr(pi)
You can create a matrix of strings. Each of its elements can contain a string with a different number of characters.
str_array = ["Имя" "Отчество" "Фамилия"; "Возраст" "Образование" "Номер телефона"]
The dimensionality of the row matrix is defined using the function size()
.
size(str_array)
Matrices consisting of rows are characterised by the same operations as numeric matrices. For example, we can output a certain row of the matrix or add another row, add a matrix row or replace an existing row of string elements.
Conclusion¶
In this article we have considered the basic functions for creating and working with strings and symbols. More information about working with strings can be found in the documentation at the link: https://engee.com/helpcenter/stable/julia/base/strings.html.