當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Julia length()用法及代碼示例


這個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))

輸出:




相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Get length of a string in Julia – length() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。