当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。