WindowsReplaceString function winrt

HSTRING WindowsReplaceString(
  1. HSTRING? string,
  2. HSTRING? stringReplaced,
  3. HSTRING? stringReplaceWith
)

Replaces all occurrences of a set of characters in the specified string with another set of characters to create a new string.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/winstring/nf-winstring-windowsreplacestring.

Implementation

HSTRING WindowsReplaceString(
  HSTRING? string,
  HSTRING? stringReplaced,
  HSTRING? stringReplaceWith,
) {
  final newString = adaptiveCalloc<Pointer>();
  final hr$ = HRESULT(
    _WindowsReplaceString(
      string ?? nullptr,
      stringReplaced ?? nullptr,
      stringReplaceWith ?? nullptr,
      newString,
    ),
  );
  if (hr$.isError) {
    free(newString);
    throw WindowsException(hr$);
  }
  final result$ = newString.value;
  free(newString);
  return .new(result$);
}