指定した文字セットに属していない文字列の最初の文字のインデックスを返します。
重要
_mbsspn および _mbsspn_l は、Windows ランタイムで実行するアプリケーションでは使用できません。 詳細については、「ユニバーサル Windows プラットフォーム アプリでサポートされていない 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関数は、strCharSetの文字セットに属していないstrの最初の文字のインデックスを返します。 検索には、終端の null 文字は含まれません。
wcsspn 関数と _mbsspn 関数は、strspn 関数のワイド文字バージョンとマルチバイト文字バージョンです。 wcsspnの引数はワイド文字列です。 _mbsspnの引数はマルチバイト文字列です。 _mbsspn はそのパラメーターを検証します。 strまたはstrCharSetがNULLされている場合は、「パラメーターの検証」で説明されているように、無効なパラメーター ハンドラー呼び出されます。 実行の継続が許可された場合、_mbspn は errno を EINVAL に設定し、0 を返します。 strspn と wcsspn はパラメーターを検証しません。 それ以外では、これらの関数の動作は同じです。
出力値は、ロケールの LC_CTYPE カテゴリ設定の設定によって影響を受けます。 詳細については、setlocaleを参照してください。 _l サフィックスが付いていないこれらの関数のバージョンでは、このロケールに依存する動作に現在のロケールを使用します。_l サフィックスが付いているバージョンは、渡されたロケール パラメーターを代わりに使用する点を除いて同じです。 詳細については、「 Locale」を参照してください。
既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT でのグローバル状態」を参照してください。
汎用テキスト ルーチンのマップ
| 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> |
互換性の詳細については、「 Compatibility」を参照してください。
例
// 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 );
}
The portion of 'cabbage' containing only a, b, or c is 5 bytes long
関連項目
文字列操作
ロケール
マルチバイト文字のシーケンスの解釈
_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