startswith
startswith(string, prefix | chars)
Returns true if string starts with prefix. If the second argument is a vector or set of characters, tests whether the first character of string belongs to that set.
Examples
julia> startswith("Julia Programming", "Julia")
true
julia> startswith("Julia Programming", "Programming")
false
julia> startswith("Julia Programming", 'J')
true
julia> startswith("Julia Programming", ['J', 'P', 'Q'])
true
-
Check if a string starts with a specific prefix:
julia> startswith("Hello World", "Hello") trueThis example returns
truebecause the string "Hello World" starts with the prefix "Hello". -
Check if a character is the first character of a string:
julia> startswith("Julia", 'J') trueIt returns
truebecause the character 'J' is the first character of the string "Julia". -
Check if the first character of a string belongs to a set of characters:
julia> startswith("Julia", ['J', 'P', 'Q']) trueIn this example, it returns
truebecause the first character of the string "Julia" (which is 'J') belongs to the set of characters ['J', 'P', 'Q'].
Common mistake example:
julia> startswith("Julia", "Jul")
false
In this example, the provided prefix is "Jul", but the string "Julia" does not start with that exact prefix. Ensure that the prefix matches the starting characters of the string accurately to get the desired result.
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.