String.index_of

String.index_of

String.index_of

Function

Returns the position of the first occurrence of the specified fragment.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
needleAnyNo''The fragment to be found will be converted into a string first when called.

Return value

TypeDescription
IntReturns the starting byte position if found; returns -1 if not found.

Example

Notes

  • The return value comes from the Rust string lookup result, and the position is calculated as a UTF-8 byte offset.