In Julia language, I want to use functions defined for Array{T,1} a.k.a. Vector{T} on a String, essentially treating it as Array{Char,1}.
An example of a function I would like to use:
julia> deleteat!("Hrello!",2)
ERROR: MethodError: no method matching deleteat!(::String, ::Int64)
Closest candidates are:
deleteat!(::Array{T,1} where T, ::Integer) at array.jl:1177
deleteat!(::Array{T,1} where T, ::Any) at array.jl:1214
deleteat!(::BitArray{1}, ::Integer) at bitarray.jl:901
...
Stacktrace:
[1] top-level scope at none:0
julia> deleteat!(['H','r','e','l','l','o','!'], 2)
6-element Array{Char,1}:
'H'
'e'
'l'
'l'
'o'
'!'
To be clear, I would like to start with a String and end up with a String, but use Array {Char,1} operations to alter the String.
Creating a Vector A Vector in Julia can be created with the use of a pre-defined keyword Vector() or by simply writing Vector elements within square brackets([]). There are different ways of creating Vector. vector_name = [value1, value2, value3,..] or vector_name = Vector{Datatype}([value1, value2, value3,..])
A 1D array can be created by simply writing array elements within square brackets separated by commas(, ) or semicolon(;). A 2D array can be created by writing a set of elements without commas and then separating that set with another set of values by a semicolon.
The replace() is an inbuilt function in julia that is used to replace a word or character with the specified string or character. Parameters: s::AbstractString: Specified string. pattern=>Word: Pattern is searched from the given sentence and then that pattern is replaced with the word.
Splitting string into array of substrings in Julia – split() and rsplit() Method. The split() is an inbuilt function in julia which is used to split a specified string into an array of substrings on occurrences of the specified delimiter(s).
In Julia, one should always try collect
firstly for getting a Vector
from something else.
julia> deleteat!(collect("Hrello!"), 2)
6-element Array{Char,1}:
'H'
'e'
'l'
'l'
'o'
'!'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With