Archived Forum Post

Index of archived forum posts

Question:

CkStringArrayW and How to split a Unicode String using split2WS

Feb 15 '16 at 10:53

I've got a Unicode string I'd like to split using split2WS, however it returns a CkStringArray not a CkStringArrayW.. Is there a more appropriate way to do this so I get a CkStringArrayW? I have searched and can't find a method that returns a Unicode string array.

Thanks!

M


Answer

This was an oversight when adding the function to the library. (What the heck was I thinking???)

Anyway, it can't be changed now, so here's a workaround:

    CkStringArray sa;

sa.Append("apple");
sa.Append("orange");
sa.Append("pear");

// Get Unicode strings from sa.

// First, tell the CkStringArray object to return utf-8
sa.put_Utf8(true);

CkString strTemp;
int i;
for (i=0; i<sa.get_Count(); i++)
{
const char *strUtf8 = sa.getString(i);
strTemp.setStringUtf8(strUtf8);
const wchar_t *wideStr = strTemp.getUnicode();
// Note: wideStr points to internal memory within strTemp.  Make sure to copy the wide string 
// to a safe place, unless the app uses it only while strTemp remains in existence and is not modified.
}