Engee documentation
Notebook

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.

In [ ]:
c = 'y'
Out[0]:
'y': ASCII/Unicode U+0079 (category Ll: Letter, lowercase)
In [ ]:
c1 = Int(c)
Out[0]:
121
In [ ]:
typeof(c1)
Out[0]:
Int64

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.

In [ ]:
str = "Hello, world"
Out[0]:
"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().

In [ ]:
length(str)
Out[0]:
12

If the text contains inverted commas, it must be enclosed in three pairs of inverted commas.

In [ ]:
str = """Текст в кавычках"""
Out[0]:
"Текст в кавычках"

To combine several characters or strings, there is a function string().

In [ ]:
A = "Первая"
B = "и вторая части строки"
C = string(A, ' ', B)
Out[0]:
"Первая и вторая части строки"

You can also concatenate multiple strings using the * character.

In [ ]:
name = "Engee"
domen = ".com"
adress = name*domen
Out[0]:
"Engee.com"

Any type of input data can be converted to a string using the function repr().

In [ ]:
str_pi = repr(pi)
Out[0]:
"π"

You can create a matrix of strings. Each of its elements can contain a string with a different number of characters.

In [ ]:
str_array = ["Имя" "Отчество" "Фамилия"; "Возраст" "Образование" "Номер телефона"]
Out[0]:
2×3 Matrix{String}:
 "Имя"      "Отчество"     "Фамилия"
 "Возраст"  "Образование"  "Номер телефона"

The dimensionality of the row matrix is defined using the function size().

In [ ]:
size(str_array)
Out[0]:
(2, 3)

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.