从 Julia 中的字符串开头获取特定大小的子字符串 – first() 方法
first()
是 julia 中的内置函数,用于返回由指定字符串的前 n 个字符组成的字符串,其中 n 将作为参数传递。
Syntax:
first(s::AbstractString, n::Integer)
Parameters:
- s::AbstractString: Specified string.
- n::Integer: Specified integer value.
Returns: It returns a string consisting of the first n characters of the specified string, where n will be passed as parameter.
示例 1:
# Julia program to illustrate
# the use of String first() method
# Getting a string consisting of the first
# n characters of the specified string
println(first("GeeksforGeeks", 0))
println(first("GeeksforGeeks", 5))
println(first("GeeksforGeeks", 8))
println(first("GeeksforGeeks", 10))
输出:
示例 2:
# Julia program to illustrate
# the use of String first() method
# Getting a string consisting of the first
# n characters of the specified string
println(first("1 + 2+3 + 4", 0))
println(first("2-4-6-8", 4))
println(first("1 * 3*5 * 7", 6))
输出: