Skip to main content
Module

x/denops_std/function/mod.ts>stridx

📚 Standard module for denops.vim
Go to Latest
function stridx
import { stridx } from "https://deno.land/x/denops_std@v6.3.0/function/mod.ts";

The result is a Number, which gives the byte index in {haystack} of the first occurrence of the String {needle}. If {start} is specified, the search starts at index {start}. This can be used to find a second match:

:let colon1 = stridx(line, ":")
:let colon2 = stridx(line, ":", colon1 + 1)

The search is done case-sensitive. For pattern searches use match(). -1 is returned if the {needle} does not occur in {haystack}. See also strridx(). Examples:

:echo stridx("An Example", "Example")      3
:echo stridx("Starting point", "Start")    0
:echo stridx("Starting point", "start")   -1

stridx() works similar to the C function strstr(). When used with a single character it works similar to strchr().

Can also be used as a method:

GetHaystack()->stridx(needle)

Parameters

denops: Denops
haystack: unknown
needle: unknown
optional
start: unknown

Returns

Promise<number>