This language bar is your friend. Select your favorite languages!

Idiom #96 Check string prefix

Set boolean b to true if string s starts with prefix prefix, false otherwise.

bool b = s.StartsWith(prefix);
#include <stdbool.h>
#include <string.h>
bool b = !strncmp(s, prefix, sizeof(prefix)-1);
import std.algorithm.searching;
b = s.startsWith(prefix);
var b = s.startsWith(prefix);
B = string:find(S, Prefix) =:= S.
import "strings"
b := strings.HasPrefix(s, prefix)
import Data.List
b = prefix `isPrefixOf` s
var b = (s.lastIndexOf(prefix, 0) === 0);
var b = s.startsWith(prefix);
boolean b = s.startsWith(prefix);
b = s:find(prefix) == 1
$b = (bool)preg_match('#^http#', $s);
b := pos(prefix, s) = 1;
$b = $prefix eq substr($s,0,length($prefix));
b =s.startswith(prefix)
b = s.start_with?(prefix)
let b = s.starts_with(prefix);
val b = s.startsWith(prefix)

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Related idioms