Find the previous occurrence of pattern in string in Julia – findprev() Method
The findprev()
is an inbuilt function in julia which is used to return the previous occurrence of the specified pattern in specified string starting from specified position.
Syntax:
findnprev(pattern::AbstractString, string::AbstractString, start::Integer)Parameters:
- pattern::AbstractString: Specified pattern
- string::AbstractString: Specified string
- start::Integer: It is the start position before which matching going to be performed.
Returns: It returns the previous occurrence of the specified pattern in a specified string starting from the specified position.
Example 1:
# Julia program to illustrate # the use of String findprev() method # Here the pattern is "g", String is # "Beginner" and position is 3 Println(findprev( "g" , "Beginner" , 3 )) # Here the pattern is "G", String is # "w3wiki" and position is 10 Println(findprev( "G" , "w3wiki" , 10 )) # Here the pattern is "for", String is # "w3wiki" and position is 8 Println(findprev( "for" , "w3wiki" , 8 )) # Here the pattern is "k", String is # "w3wiki" and position is 7 Println(findprev( "k" , "w3wiki" , 7 )) |
Output:
Example 2:
# Julia program to illustrate # the use of String findprev() method # Here the pattern is "23", String is # "12345" and position is 5 Println(findprev( "23" , "12345" , 5 )) # Here the pattern is "23", String is # "12345" and position is 4 Println(findprev( "23" , "12345" , 4 )) # Here the pattern is "3", String is # "123123" and position is 6 Println(findprev( "3" , "123123" , 6 )) # Here the pattern is "123", String is # "123123123" and position is 7 Println(findprev( "123" , "123123123" , 7 )) |
Output: