0

I can't find a duplicate for this particular question although there are similar ones for different languages.

I am trying to split a string into tokens where my delimiter is a two-character string.

My questions is : 1. Is it possible to do it with _tcstok_s because MSDN says that it takes a set of characters as delimiter where it will match for any of those characters? 2. If it is not possible to do it with _tcstok_s, any other function which can do it. My strings are TCHARs and I would like to use an in-built function as much as possible.

Thanks!

Akshat Goel
  • 538
  • 4
  • 18

1 Answers1

0

Couldn't find a inbuilt function which does this. I am using the following,

TCHAR *str=TEXT("mango, banana, apple");

std::wstring paramStr(str);
std::wstring delimiter = L", ";
size_t pos = 0;
std::string token;

while ((pos = paramStr.find(delimiter)) != std::string::npos) {
    token = paramStr.substr(0, pos);
    std::cout << token << std::endl;
    paramStr.erase(0, pos + delimiter.length());
}

std::cout << paramStr << std::endl;
Vindhya
  • 49
  • 7