ฟังก์ชัน strspn() ใช้ในการคำนวณความยาวของสตริงย่อยของสตริงแรกซึ่งมีอยู่ในสตริงที่สอง ส่งคืนความยาวของสตริงย่อยนั้น
นี่คือไวยากรณ์ของ strspn() ในภาษา C
size_t strspn(const char *string1, const char *string2);
นี่คือตัวอย่าง strspn() ในภาษา C
ตัวอย่าง
#include <stdio.h>
#include<string.h>
int main() {
const char s1[] = "Helloworld!";
const char s2[] = "Hello";
int length = strspn(s1, s2);
printf("The length of string : %d", length);
return 0;
} ผลลัพธ์
The length of string : 5