Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
var i = x.IndexOf(y);
i wil be -1 if y is not found in x.
var i = x.indexOf(y);
defmodule Dry do
def indexOf(x, y, default \\ -1) do
case String.split(x, y, parts: 2) do
[head, _] -> String.length(head)
[_] -> default
end
end
end
See "Elixir Lang Core" [Doc] for discussion on integration into core Elixir
TL;DR NO
# Outside of module
case String.split(haystack, needle, parts: 2) do
[head, _] -> String.length(head)
[_] -> -1
end
TL;DR NO
# Outside of module
case String.split(haystack, needle, parts: 2) do
[head, _] -> String.length(head)
[_] -> -1
end
I=index(x,y)
let i = x.indexOf(y);
This sets i to -1 if y is not found in x.
$i = mb_strpos($x, $y, 0, 'UTF-8');
Requires multibyte string extension.
i := Pos(y, x);
i will be 0 (zero) if y is not a substring of x. the Pos() function is case sensitive.
$i = index($x, $y);