Skip to content

strncmp

Compare the first n characters of two strings (case-sensitive).

tf = strncmp(str1, str2, n)

Returns true when the first n characters of str1 and str2 are identical (including case), false otherwise.

strncmp('hello world', 'hello there', 5) % 1
strncmp('hello world', 'hello there', 6) % 0
  • strcmp — Compare strings for equality (case-sensitive).
  • strncmpi — Compare the first n characters of two strings (case-insensitive).