searchindex
searchindex(string, substring, [start])
Similar to search
, but return only the start index at which the substring is found, or 0
if it is not.
Examples
julia> searchindex("Julia is a high-level programming language", "Julia")
1
julia> searchindex("Julia is a high-level programming language", "programming")
19
julia> searchindex("Julia is a high-level programming language", "Python")
0
julia> searchindex("Julia is a high-level programming language", "programming", 20)
23
This function searchindex
is used to find the start index at which a substring is found within a given string. If the substring is not found, it returns 0
.
Here are some common examples of how to use searchindex
:
-
Find the index of a substring in a string:
julia> searchindex("Julia is a high-level programming language", "Julia") 1
In this example, the substring "Julia" is found at index 1 in the given string.
-
Find the index of a different substring:
julia> searchindex("Julia is a high-level programming language", "programming") 19
Here, the substring "programming" is found at index 19 in the string.
-
Handle cases where the substring is not found:
julia> searchindex("Julia is a high-level programming language", "Python") 0
The function returns
0
if the substring is not found in the given string. - Specify a start index for searching:
julia> searchindex("Julia is a high-level programming language", "programming", 20) 23
By specifying a start index of 20, the function only searches for the substring after that position. In this case, the substring "programming" is found at index 23.
Note: The searchindex
function is case-sensitive.
See Also
ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.