startsWith

Checks if C string p starts with needle.

@system pure nothrow @nogc
bool
startsWith
(
scope const(char)* p
,
scope const(char)[] needle
)

Parameters

p const(char)*

the C string to check

needle const(char)[]

the string to look for

Return Value

Type: bool

true if p starts with needle

Examples

const buf = "123".toStaticArray;
const ptr = &buf[0];
assert(ptr.startsWith(""));
assert(ptr.startsWith("1"));
assert(ptr.startsWith("12"));
assert(ptr.startsWith("123"));
assert(!ptr.startsWith("1234"));

Meta