c='a'
#'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
typeof(c)
#Char
c=Int(c)
c
#97
typeof(c)
#Int64
Char(97)
#'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
'A' < 'a'
#true
'A' +1
#'B': ASCII/Unicode U+0042 (category Lu: Letter, uppercase)
由双引号或三重双引号分隔
"
) 通常用于定义单行字符串str="Hello world"
str
# "Hello world"
"""
) 可以用于定义多行字符串。
s = """This is a multiline
string in Julia."""
s
#"This is a multiline\nstring in Julia."
s = """He said, "Hello, Julia!" without any issues."""
s
#"He said, \"Hello, Julia!\" without any issues."
\
) 来将其分割。
str="Hello \
world"
str
#"Hello world"
可以使用数字(索引从1开始),也可以是begin和end(他们俩可以视作普通值,可以直接在上面进行计算)
str="Hello world"
str
#"Hello world"
str[begin]
#'H': ASCII/Unicode U+0048 (category Lu: Letter, uppercase)
str[1]
#'H': ASCII/Unicode U+0048 (category Lu: Letter, uppercase)
str[end]
#'d': ASCII/Unicode U+0064 (category Ll: Letter, lowercase)
str[begin*3]
#'l': ASCII/Unicode U+006C (category Ll: Letter, lowercase)
str[begin-1]
'''
BoundsError: attempt to access 11-codeunit String at index [0]
Stacktrace:
[1] checkbounds
@ .\strings\basic.jl:216 [inlined]
[2] codeunit
@ .\strings\string.jl:117 [inlined]
[3] getindex(s::String, i::Int64)
@ Base .\strings\string.jl:238
[4] top-level scope
@ In[48]:1
'''
str[end+1]
'''
BoundsError: attempt to access 11-codeunit String at index [12]
Stacktrace:
[1] checkbounds
@ .\strings\basic.jl:216 [inlined]
[2] codeunit
@ .\strings\string.jl:117 [inlined]
[3] getindex(s::String, i::Int64)
@ Base .\strings\string.jl:238
[4] top-level scope
@ In[49]:1
'''
str[3:4]
#"ll"
greet = "Hello"
whom = "world"
string(greet, ", ", whom, ".\n")
#"Hello, world.\n"
greet = "Hello"
whom = "world"
greet * ", " * whom * ".\n"
#"Hello, world.\n"
greet = "Hello"
whom = "world"
"$greet, $whom.\n"