Share via


strspn、wcsspn、_mbsspn、_mbsspn_l

文字列の中で、文字セットに含まれない最初の文字へのインデックスを返します。

重要

_mbsspn および _mbsspn_l は、Windows ランタイムで実行するアプリケーションでは使用できません。詳細については、「/ZW でサポートされない CRT 関数」を参照してください。

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 関数は、str 文字列の中で、strCharSet の文字セットに含まれない最初の文字へのインデックスを返します。 検索には、終端の NULL 文字は含まれません。

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