The Windows Runtime string type, HSTRING
is immutable and is reference counted.
The Platform::String
type in C++/CX is simply a wrapper around the HSTRING
type and the handful of operations that it supports (see the functions that start with Windows
in the Windows Runtime C++ Functions list).
There are no operations that mutate the string because the string type is immutable (hence why there is no Replace
). There are a few non-mutating operations (certainly fewer than C++'s std::wstring
).
Platform::String
does provide Begin()
and End()
member functions (and non-member begin()
and end()
overloads) that return random access iterators into the string (they return pointers, wchar_t const*
, and pointers are valid random access iterators). You can use these iterators with any of the C++ Standard Library algorithms that take random access iterators and do not attempt to mutate the underlying sequence. For example, consider using std::find
to find the index of the first occurrence of a character.
If you need to mutate a string, use std::wstring
or std::vector<wchar_t>
. Ideally, consider using the C++ std::wstring
as much as possible in your program and only use the C++/CX Platform::String
where you need to interoperate with other Windows Runtime components (i.e., across the ABI boundary).
Platform::String
solves? (Note: You cannot use a time machine as part of your solution.) – Emaciationstd::string
doesn't? – Whoreson