Int to String in Julia

Find this useful? Support us: Star on GitHub 6
Category: Type | Language: Julia

Sure! To convert an integer to a string, you can use the string() function in Julia. Here's an example:

julia> x = 123
123

julia> typeof(x)
Int64

julia> str_x = string(x)
"123"

julia> typeof(str_x)
String

In the above example, x is an integer and we use the string() function to convert it to a string, which we save in the str_x variable. We can see that the type of x is Int64, whereas the type of str_x is String.

You can also convert a vector or an array of integers to a vector or an array of strings using the string() function. Here's an example:

julia> y = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> str_y = string.(y)
3-element Vector{String}:
"1"
"2"
"3"

In the above example, we use the dot . notation to apply the string() function to each element of the y vector, resulting in a vector of strings (i.e., str_y).