julia> (dane[1,5])
"TEST"
julia> split(dane[1,5],"")
4-element Array{SubString{String},1}:
"T"
"E"
"S"
"T"
'''
is ok,
but
'''
julia> split.(string.(dane[:,5],""))
1074955-element Array{Array{SubString{String},1},1}:
["TEST"]
["VENDI", "SERVIS", "Sp", "z", "oo"]
how to take all chars from this array not rows?
Paul
I am not exactly sure what you want to do or what type dane
is, but here are a few examples that could help.
julia> a = ["asdxsad" "axsdaxds"; "fxssd" "dasd"]
2Ă—2 Array{String,2}:
"asdxsad" "axsdaxds"
"fxssd" "dasd"
julia> split.(a,"x")
2Ă—2 Array{Array{SubString{String},1},2}:
["asd", "sad"] ["a", "sda", "ds"]
["f", "ssd"] ["dasd"]
julia> split.(a[:,2],"x")
2-element Array{Array{SubString{String},1},1}:
["a", "sda", "ds"]
["dasd"]
julia> split.(a[:],"x")
4-element Array{Array{SubString{String},1},1}:
["asd", "sad"]
["f", "ssd"]
["a", "sda", "ds"]
["dasd"]
julia> join(a," ")
"asdxsad fxssd axsdaxds dasd"
julia> split(join(a," "),"x")
5-element Array{SubString{String},1}:
"asd"
"sad f"
"ssd a"
"sda"
"ds dasd"
1 Like
With strings specifically, I’d go with split(join(array_of_strings), "")
to get characters as strings or collect(join(array_of_strings))
to get them as Char
s.
1 Like
Don’t use split(s, "")
to get “characters” — that returns 1-character strings, but Julia (unlike Python) has an actual character type. Use collect
to get an array of characters.
(That being said, it’s rare to actually need to explicitly collect an array of characters during string processing — you can just loop over the characters directly. Unlike other dynamic languages, you don’t have to cram everything into “vectorized” operations to get good performance; often non-vectorized code is clearer and faster.)
12 Likes
I think your parentheses is messed up.
split.(string.(dane[:,5]),"")
Like other mentioned, you might want array of Char
collect.(dane[:,5])
1 Like
I just wrote up a comprehensive article on splitting strings in Julia: The only way you should be splitting a String in Julia — Julia Base.split() | by Logan Kilpatrick | Sep, 2022 | Medium if you think I missed anything big, let me know!
1 Like