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
Type: const(char)*

the C string to check

needle
Type: const(char)[]

the string to look for

Return Value

Type: bool

true if p starts with needle

Examples

1 const buf = "123".toStaticArray;
2 const ptr = &buf[0];
3 assert(ptr.startsWith(""));
4 assert(ptr.startsWith("1"));
5 assert(ptr.startsWith("12"));
6 assert(ptr.startsWith("123"));
7 assert(!ptr.startsWith("1234"));

Meta