strspn() 函式在 C 語言中


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

更新於: 2020 年 6 月 24 日

152 瀏覽次數

開啟你的 職業生涯

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.