How to split a UnicodeString in C++Builder

1.2k views Asked by At

In C++ Builder (10.3 in my case), I don't know how to work with their types (in this case, their System::UnicodeString). I don't know how to split that or simply just get a standard C++ string that I could split.

1

There are 1 answers

0
manlio On

You can use the SplitString function.

It returns an array of strings of type System.Types.TStringDynArray that contains the split parts of the original string.

Example outline:

#include <System.StrUtils.hpp>

// ...

{
  UnicodeString str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
  UnicodeString delims = ", ;.";

  DynamicArray<UnicodeString> split = SplitString(str, delims);

  for (int i = split.Low; i <= split.High; ++i)
    if (!split[i].IsEmpty())  // consecutive delimiters produce empty strings
    {
      /* word processing */
    }
}