Get the first occurrence of the specified string pattern in Julia – findfirst() Method
The findfirst()
is an inbuilt function in julia which is used to return the first occurrence of the specified pattern in 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 first number is the first position of occurrence of the pattern in the specified string whereas second number is the position in the string where the pattern ends.
Example 1:
# Julia program to illustrate # the use of String findfirst() method # Here the patter is "g" and String is # "geeks" Println(findfirst( "g" , "geeks" )) # Here the patter is "eek" and String is # "geeks" Println(findfirst( "eek" , "geeks" )) # Here the patter is "ks" and String is # "geeks" Println(findfirst( "ks" , "geeks" )) # Here the patter is "geeks" and String is # "geeksforgeeks" Println(findfirst( "geeks" , "geeksforgeeks" )) |
chevron_right
filter_none
Output:
Example 2:
# 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" )) |
chevron_right
filter_none
Output: