View source code Display the source code in std/string.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.string.index_of - multiple declarations

Function indexOf

Searches for character in range.

Prototype

ptrdiff_t indexOf(Range)(
  Range s,
  dchar c,
  CaseSensitive cs = CaseSensitive.yes
)
if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range));

Parameters

NameDescription
s string or InputRange of characters to search in correct UTF format
c character to search for
cs CaseSensitive.yes or CaseSensitive.no

Returns

the index of the first occurrence of c in s. If c is not found, then -1 is returned. If the parameters are not valid UTF, the result will still be in the range [-1 .. s.length], but will not be reliable otherwise.

Function indexOf

Prototype

ptrdiff_t indexOf(Char1, Char2)(
  const(Char1)[] s,
  const(Char2)[] sub,
  size_t startIdx,
  CaseSensitive cs = CaseSensitive.yes
) @safe
if (isSomeChar!Char1 && isSomeChar!Char2);

Parameters

NameDescription
s string to search
sub substring to search for
startIdx the index into s to start searching from
cs CaseSensitive.yes or CaseSensitive.no

Returns

The index of the first occurrence of sub in s with respect to the start index startIdx. If sub is not found, then -1 is returned. If sub is found the value of the returned index is at least startIdx. startIdx represents a codeunit index in s. If the sequence starting at startIdx does not represent a well formed codepoint, then a std.utf.UTFException may be thrown.

cs indicates whether the comparisons are case sensitive.

Function indexOf

Searches for substring in s.

Prototype

ptrdiff_t indexOf(Range, Char)(
  Range s,
  const(Char)[] sub,
  CaseSensitive cs = CaseSensitive.yes
)
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char);

Parameters

NameDescription
s string or ForwardRange of characters to search in correct UTF format
sub substring to search for
cs CaseSensitive.yes or CaseSensitive.no

Returns

the index of the first occurrence of sub in s. If sub is not found, then -1 is returned. If the arguments are not valid UTF, the result will still be in the range [-1 .. s.length], but will not be reliable otherwise.

Bugs

Does not work with case insensitive strings where the mapping of tolower and toupper is not 1:1.

Function indexOf

Searches for character in range starting at index startIdx.

Prototype

ptrdiff_t indexOf(Range)(
  Range s,
  dchar c,
  size_t startIdx,
  CaseSensitive cs = CaseSensitive.yes
)
if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range));

Parameters

NameDescription
s string or InputRange of characters to search in correct UTF format
c character to search for
startIdx starting index to a well-formed code point
cs CaseSensitive.yes or CaseSensitive.no

Returns

the index of the first occurrence of c in s. If c is not found, then -1 is returned. If the parameters are not valid UTF, the result will still be in the range [-1 .. s.length], but will not be reliable otherwise.

Authors

Walter Bright, Andrei Alexandrescu, and Jonathan M Davis

License

Boost License 1.0.

Comments