Monday 8 February 2016

Julia: Characters


A character is used to represent a single character, enclosed in single quotes ('x'). Size of char in Julia is 32 bits.

julia> data='A'
'A'

julia> typeof(data)
Char

Convert character to integer value
By using Int() function, you can convert a character to integer value.

julia> Int('A')
65

julia> Int('Z')
90

Convert an integer to character value

By using Char() function, you can convert a character to integer.

julia> Char(65)
'A'

julia> Char(90)
'Z'


Check whether an integer is valid uni code char or not
By using isvalid() function, you can check whether an integer value can be converted to valid character or not.

julia> isvalid(Char,1234)
true

julia> Char(1234)
'Ӓ'

julia> isvalid(Char,4294967)
false

julia> Char(4294967)
'\U418937'


Comparison operators Vs Characters
You can apply comparison operators to characters also. When you compare two characters, it internally compares the Unicode values for the characters.

julia> Int('A')
65

julia> Int('a')
97

julia> 'A' < 'a'
true

julia> 'A' > 'a'
false


You can perform some arithmetic operations like +, - on characters.

julia> 'A' - 'a'
-32

julia> 'A' + 1
'B'



Previous                                                 Next                                                 Home

No comments:

Post a Comment