Logo

Programming-Idioms

  • C
  • C#

Idiom #96 Check string prefix

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

Are the first characters of s equal to this prefix?
bool b = s.StartsWith(prefix);
#include <stdbool.h>
#include <string.h>
bool b = !strncmp(s, prefix, sizeof(prefix)-1);
with Ada.Strings.Fixed;
B := Ada.Strings.Fixed.Index (S, Prefix) = S'First;

New implementation...