Problem with "\" , how to use in Dict {Any}?


#1

julia> usuwam
Dict{Any,Any} with 6 entries:
"=" => “”
"!" => “”
"-" => “”
"/" => “”
"’’" => “”
"+" => “”

Is ok, but :
julia> get!(usuwam,“backslash”,"")
not work ! how to use “backslash” in Dict {Any} ?
Paul


#2

I think you want "\\". See https://en.wikipedia.org/wiki/C_syntax#Backslash_escapes

Note also that if your dictionary keys are all single characters, you can use Char instead of String, i.e. '=', '\\', etcetera. Note also that you can have a typed dictionary, e.g. Dict{String,String} or Dict{Char,String}.

https://xkcd.com/1638/


#3

Unfrotunatly , \ no works :confused:

get!(B,"\","")
"“
B
Dict{String,String} with 3 entries:
”," => “”
":" => “”
"\" => “”

replace(x,’\’,‘u’)
“adam\a”

replace(x,‘a’,‘u’)
“udum\a”

replace(x,’\’,‘u’)
“adam\a”

replace(x,"\",‘u’)
“adam\a”

Some ideas ?
Paul

W dniu 2018-02-11 o 13:35, Steven G. Johnson pisze:


#4

Please provide a minimal working example, with code that can be copied and pasted, as well as describing precisely what you expect to happen.


#5

A have to clearing text from dirti HTML like dhis:

only=sort(split(text_only(doc.root[2]) ))
2472-element Array{SubString{String},1}:
"!"
"""
"“Bezlitosny”
"“Była”
"“Coś”
"“Decyzja”
"“Diablo”"
"“Dzień”
"“Elisabeth,”
"“Familiady”"
"“Lampka”
"“Loteria”

and now i am makeing Dict with NoLeters Char to remove it
backslash is one of this…
my list:
!


#6

Please provide a simplified version that everybody can copy and paste to define the variables.

Also, please quote your code using backticks (`)


#7

`
julia> get!(x,’!’,"")
""

julia> get!(x,’’,"")
ERROR: syntax: invalid character literal
julia> get!(x,’\’,"")
"“
julia> x
Dict{Char,String} with 4 entries:
’!’ => “”
’\’ => “”
’ ’ => “”
’”’ => “”
`


#8

Char(92) == ‘\’ # true


#9

You must escape the backslash character, as for example '\\'. Note there are two backslashes written here, but this is actually a single backslash character.