strspn、wcsspn、_mbsspn、_mbsspn_l

返回第一个字符的索引,在字符串中,它不属于字符集。

重要

_mbsspn 和 _mbsspn_l 不能在 Windows 运行时执行的应用程序中使用。有关详细信息,请参见 CRT functions not supported with /ZW(CRT 函数不支持使用/ZW)。

size_t strspn(
   const char *str,
   const char *strCharSet 
);
size_t wcsspn(
   const wchar_t *str,
   const wchar_t *strCharSet 
);
size_t _mbsspn(
   const unsigned char *str,
   const unsigned char *strCharSet 
);
size_t _mbsspn_l(
   const unsigned char *str,
   const unsigned char *strCharSet,
   _locale_t locale
);

参数

  • str
    要搜索的 null 终止的字符串。

  • strCharSet
    null 终止的字符集。

  • locale
    要使用的区域设置。

返回值

返回指定完全包含在 strCharSet*.的str子字符串的长度整数值。如果 str 从不在 strCharSet的一个字符开始,* 该函数返回 0。

备注

strspn 函数返回不属于strCharSet的字符集的str 的第一个字符的索引。 搜索不包括终止空字符。

wcsspn 和 _mbsspn 是宽字符,属于 strspn **.**的多节字字符版本。wcsspn参数是宽字符字符串;_mbsspn参数是多字节字符字符串。 _mbsspn验证其参数。 如果 str 或strCharSet为 NULL,则将调用无效参数处理程序,如参数验证 所述。 如果允许执行继续,则将 _mbspn将 errno 设置为 EINVAL,并且返回0。 strspn 和 wcsspn 不验证其参数。 否则这三个函数否则具有相同行为。

输出值受区域设置的 LC_CTYPE 类设置影响;有关更多信息,请参见 setlocale。 这些不带 _l 后缀的函数的版本使用为该区域设置相关的行为的当前区域设置;带有 _l 后缀的版本相同,只不过它们使用传递的区域设置参数。 有关详细信息,请参阅区域设置

一般文本例程映射

TCHAR.H 例程

未定义 _UNICODE & _MBCS

已定义 _MBCS

已定义 _UNICODE

_tcsspn

strspn

_mbsspn

wcsspn

_mbsspn_l

要求

例程

必需的标头

strspn

<string.h>

wcsspn

<string.h> 或 <wchar.h>

_mbsspn, _mbsspn_l

<mbstring.h>

有关兼容性的更多信息,请参见兼容性

示例

// crt_strspn.c
// This program uses strspn to determine
// the length of the segment in the string "cabbage"
// consisting of a's, b's, and c's. In other words,
// it finds the first non-abc letter.
//

#include <string.h>
#include <stdio.h>

int main( void )
{
   char string[] = "cabbage";
   int  result;
   result = strspn( string, "abc" );
   printf( "The portion of '%s' containing only a, b, or c "
           "is %d bytes long\n", string, result );
}
  

.NET Framework 等效项

System::String::Substring

请参见

参考

字符串操作 (CRT)

区域设置

多字节字符序列的解释

_strspnp、_wcsspnp、_mbsspnp、_mbsspnp_l

strcspn、wcscspn、_mbscspn、_mbscspn_l

strncat、_strncat_l、wcsncat、_wcsncat_l、_mbsncat、_mbsncat_l

strncmp、wcsncmp、_mbsncmp、_mbsncmp_l

strncpy、_strncpy_l、wcsncpy、_wcsncpy_l、_mbsncpy、_mbsncpy_l

_strnicmp、_wcsnicmp、_mbsnicmp、_strnicmp_l、_wcsnicmp_l、_mbsnicmp_l

strrchr、wcsrchr、_mbsrchr、_mbsrchr_l