FirstFromLeft - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

StringTools

 FirstFromLeft
 locate the first occurrence of a character from the beginning of a string
 FirstFromRight
 locate the first occurrence of a character from the end of a string

 Calling Sequence FirstFromLeft( char, s ) FirstFromRight( char, s )

Parameters

 char - string; character to search for s - string; string to search in

Description

 • The FirstFromLeft(char, s) function returns the index of the first occurrence of character char in the string s, counting from the left (or beginning) of the string. If character char does not occur in string s, the value 0 is returned.
 Parameter char must be a string of length at least one. Only the first character of the string is used. Therefore, it is not necessary to create a new one-character string to perform this test if it is the first character of an existing string.
 • The FirstFromRight(char, s) function is similar to FirstFromLeft except that the index of the first occurrence of the character searching from the right end of the string is returned.
 • These functions are part of the StringTools package, and so they can be used in the form FirstFromLeft(..) only after executing the command with(StringTools). However, they can always be accessed through the long form of the command by using the form StringTools[FirstFromLeft](..).
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{idx}≔\mathrm{FirstFromLeft}\left("b","abcde"\right)$
 ${\mathrm{idx}}{≔}{2}$ (1)
 > ${"abcde"}_{\mathrm{idx}}$
 ${"b"}$ (2)
 > $\mathrm{FirstFromLeft}\left("x","abcde"\right)$
 ${0}$ (3)
 > $\mathrm{FirstFromLeft}\left("bx","abcde"\right)$
 ${2}$ (4)
 > $\mathrm{idx}≔\mathrm{FirstFromRight}\left("x","axbcxa"\right)$
 ${\mathrm{idx}}{≔}{5}$ (5)
 > ${"axbcxa"}_{\mathrm{idx}}$
 ${"x"}$ (6)
 > $\mathrm{FirstFromRight}\left("x",\mathrm{Random}\left(10000\right)\right)$
 ${9968}$ (7)
 > $\mathrm{FirstFromRight}\left("x","abcde"\right)$
 ${0}$ (8)