函式
<cwchar>

wcsstr

const wchar_t* wcsstr (const wchar_t* wcs1, const wchar_t* wcs2);      wchar_t* wcsstr (      wchar_t* wcs1, const wchar_t* wcs2);
定位寬字串的子串
返回第一個出現的wcs2wcs1中的指標,如果wcs2不是wcs1的一部分,則返回空指標。

匹配過程不包括終止的空寬字元,但在那裡停止。

這是strstr<cstring>)的寬字元等價物。

引數

wcs1
要被掃描的 C 寬字串。
wcs2
包含要匹配字元序列的C寬字串。

返回值

指向wcs1wcs2指定的整個字元序列的第一個出現的指標,如果該序列在wcs1中不存在,則為nullptr。

可移植性

在 C 語言中,此函式僅宣告為

wchar_t * wcsstr ( const wchar_t *, const wchar_t * );

而不是 C++ 中提供的兩個過載版本。

示例

1
2
3
4
5
6
7
8
9
10
11
12
/* wcsstr example */
#include <wchar.h>

int main ()
{
  wchar_t wcs[] = L"This is a simple string";
  wchar_t * pwc;
  pwc = wcsstr (wcs,L"simple");
  wcsncpy (pwc,L"sample",6);
  wprintf (L"%ls\n",wcs);
  return 0;
}
此示例搜尋L"simple"wcs中的子字串,並將該單詞替換為L"sample".

輸出

This is a sample string


另見