這個length()
是 julia 中的一個內置函數,用於返回具有所需起始和結束位置的指定字符串的長度。
用法:
length(S::AbstractString)
or
length(S::AbstractString, i::Integer, j::Integer)
參數:
- S::抽象字符串:指定字符串
- 我::整數:包含起始位置。
- 我::整數:包含結束位置。
返回值:它返回具有所需起始和結束位置的指定字符串的長度。
範例1:
# Julia program to illustrate
# the use of String length() method
# Finding the length of the string
# "Geeks"
println(length("Geeks"))
# Finding the length of the string
# "Geeks" from 2nd to 4th position
println(length("Geeks", 2, 4))
# Finding the length of the string
# "Geeks" from 2nd to 5th position
println(length("Geeks", 2, 5))
# Finding the length of the string
# "GeeksforGeeks"
println(length("GeeksforGeeks"))
# Finding the length of the string
# "GeeksforGeeks" from 2nd to 2nd position
println(length("GeeksforGeeks", 2, 2))
# Finding the length of the string
# "GeeksforGeeks" from 4th to 10th position
println(length("GeeksforGeeks", 4, 10))
輸出:
範例2:
# Julia program to illustrate
# the use of String length() method
# Finding the length of the string
# "12345"
println(length("12345"))
# Finding the length of the string
# "12345" from 2nd to 4th position
println(length("12345", 2, 4))
# Finding the length of the string
# "2468" from 1st to 3rd position
println(length("2468", 2, 3))
輸出:
相關用法
- Julia SubString()用法及代碼示例
- Julia length()用法及代碼示例
- Julia sizeof()用法及代碼示例
- Julia findlast()用法及代碼示例
- Julia repeat()用法及代碼示例
- Julia findfirst()用法及代碼示例
- Julia first()用法及代碼示例
- Julia last()用法及代碼示例
- Julia Array findall()用法及代碼示例
- Julia Array findprev()用法及代碼示例
- Julia Array findnext()用法及代碼示例
- Julia Array findfirst()用法及代碼示例
- Julia Array findlast()用法及代碼示例
- Julia ndims()用法及代碼示例
- Julia size()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Get length of a string in Julia – length() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。