當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Julia findnext()用法及代碼示例


findnext() 是 julia 中的一個內置函數,用於返回從指定位置開始的指定字符串中指定模式的下一次出現。

用法:

findnext(pattern::AbstractString, string::AbstractString, start::Integer)

參數:

  • 模式::抽象字符串:指定花樣
  • 字符串::抽象字符串:指定字符串
  • 開始::整數:它是將要執行匹配的起始位置。

返回值:它返回從指定位置開始的指定字符串中指定模式的下一次出現。

範例1:

Python




# Julia program to illustrate
# the use of String findnext() method
  
# Here the pattern is "g", String is
# "geeks" and position is 1
Println(findnext("g", "geeks", 1))
 
# Here the pattern is "G", String is
# "GeeksforGeeks" and position is 6
Println(findnext("G", "GeeksforGeeks", 6))
 
# Here the pattern is "e", String is
# "GeeksforGeeks" and position is 5
Println(findnext("G", "GeeksforGeeks", 5))
 
# Here the pattern is "k", String is
# "GeeksforGeeks" and position is 2
Println(findnext("G", "GeeksforGeeks", 2))

輸出:

範例2:

Python


# Julia program to illustrate
# the use of String findnext() method
  
# Here the pattern is "23", String is
# "12345" and position is 1
Println(findnext("23", "12345", 1))
 
# Here the pattern is "23", String is
# "12345" and position is 2
Println(findnext("23", "12345", 2))
 
# Here the pattern is "3", String is
# "12345" and position is 5
Println(findnext("3", "12345", 5))
 
# Here the pattern is "123", String is
# "123123123" and position is 4
Println(findnext("123", "123123123", 4))

輸出:




相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Find the next occurrence of pattern in string in Julia – findnext() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。