Get the first occurrence of the specified string pattern in Julia – findfirst() Method

The findfirst() is an inbuilt function in julia that is used to return the first occurrence of the specified pattern in a specified string.
 

Syntax: 

findfirst(Pattern::AbstractString, String::AbstractString)

Parameters: 

  • Pattern: Specified pattern to be searched
  • String: Specified string

Returns: It returns a number in the format of First_number:Second_number. Where the first number is the first position of occurrence of the pattern in the specified string whereas the second number is the position in the string where the pattern ends. 
 

Example 1: 

Python




# Julia program to illustrate
# the use of String findfirst() method
  
# Here the pattern is "g" and String is
# "Beginner"
Println(findfirst("g", "Beginner"))
  
# Here the pattern is "eek" and String is
# "Beginner"
Println(findfirst("eek", "Beginner"))
  
# Here the pattern is "ks" and String is
# "Beginner"
Println(findfirst("ks", "Beginner"))
  
# Here the pattern is "Beginner" and String is
# "w3wiki"
Println(findfirst("Beginner", "w3wiki"))


Output: 
 

Example 2: 

Python




# Julia program to illustrate
# the use of String findfirst() method
  
# Here the pattern is "4" and String is
# "2468"
Println(findfirst("4", "2468"))
  
# Here the pattern is "234" and String is
# "123456"
Println(findfirst("234", "123456"))
  
# Here the pattern is "45" and String is
# "123456"
Println(findfirst("45", "123456"))


Output: 
 

 



Contact Us