WindowsReplaceString 函数 (winstring.h)

将指定字符串中一组字符的所有匹配项替换为另一组字符以创建新字符串。

语法

HRESULT WindowsReplaceString(
  HSTRING string,
  HSTRING stringReplaced,
  HSTRING stringReplaceWith,
  HSTRING *newString
);

参数

string

类型:[in] HSTRING

原始字符串。

stringReplaced

类型:[in] HSTRING

要替换的字符串。

stringReplaceWith

类型:[in] HSTRING

要替换 stringReplaced 的所有匹配项的字符串。 如果此参数为 NULL,则删除 stringReplaced 的所有实例。

newString

类型:[out] HSTRING*

一个等效于原始的字符串,只不过 stringReplaced 的所有实例都替换为 stringReplaceWith

返回值

类型: HRESULT

此函数可以返回其中一个值。

返回代码 说明
S_OK
字符串替换成功。
E_INVALIDARG
newStringNULLstringReplaced 为空,或 string1 的长度加上 string2 的长度大于 MAXUINT32,即 4,294,967,295;即十六进制0xFFFFFFFF。
E_OUTOFMEMORY
未能分配新字符串。

注解

每次对 WindowsReplaceString 函数的调用都必须与对 WindowsDeleteString 的相应调用匹配。

要求

   
最低受支持的客户端 Windows 8 [桌面应用 |UWP 应用]
最低受支持的服务器 Windows Server 2012 [桌面应用 |UWP 应用]
目标平台 Windows
标头 winstring.h

另请参阅

WindowsDeleteString