C++ cstring strcspn() 函式
示例
測量字串中第一個標點符號之前的部分長度
char myStr[] = "Learn C++, Java and Python!";
int pos = strcspn(myStr, ",.!?");
cout << pos;
自己動手試一試 »
定義和用法
strcspn() 函式在 C 風格字串中搜索指定字元的任何一個首次出現,並返回到該點為止的字串長度。如果找不到任何字元,則返回字串的長度。
strcspn() 函式定義在 <cstring>
標頭檔案中。
語法
strcspn(void * str, void * search);
引數值
引數 | 描述 |
---|---|
str | 必需。要搜尋的字串。 |
search | 必需。包含要搜尋的字元集的字串。 |
技術詳情
返回 | 一個整數,表示第一個搜尋字元的出現位置,或者在未找到任何字元時表示字串的長度。 |
---|