Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Get a substring of specific size from starting of a string in Julia – first() Method

  • Last Updated : 26 Mar, 2020

The first() is an inbuilt function in julia which is used to return a string consisting of the first n characters of the specified string, where n will be passed as parameter.

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.

Example 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))

Output:

Example 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))

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :