mercredi 9 juin 2021

Split wchar_t on size

I want split a wchar_t string on size: e.g. wchar_t* t= L"Abcdefghijk" and I want to split on size 4 then the chunks I should get are: {"Abcd", "efgh", "ijk"}

I wrote the following code for doing this, however it has bugs:

    int maxSize=10;
    while ((lqs > maxSize) && (it < lqs))
    {
        wchar_t *strng = (wchar_t*)calloc(2, sizeof(wchar_t));
        int fragLen = 0;

        while ((it < lqs) && (fragLen < maxSize))
        {
            wcsncat_s(strng, (wcslen(strng) + 1) * 2, &queryShapeTemp[it], 1);
            ++it;
            ++fragLen;
        }
        
        lqs = lqs - maxSize;
        free(strng);
    }

Is there an efficient way of splitting strings or chunking strings based on size without using "std::wstring" or other stl libraries?

Aucun commentaire:

Enregistrer un commentaire