Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this string:

T;150;;cha;;22052024;Glo snc;;;;


I have to tokenize but the first string is T, then 150 and then cha,
But I want:

T 150 and empty string and not cha..how must I do?

i WROTE:

CString strToken = str_line.Tokenize(_T(";"), nTokenPos);
strToken = str_line.Tokenize(_T(";"), nTokenPos);


What I have tried:

I tried to use this code but it doesn't read empty string..
Posted
Comments
PIEBALDconsult 23-Feb-24 11:18am    
How about a Regular Expression?
Member 14594285 23-Feb-24 11:19am    
I don't understand
jeron1 23-Feb-24 12:27pm    
https://en.wikipedia.org/wiki/Regular_expression

 
Share this answer
 
Comments
CPallini 24-Feb-24 4:27am    
Nice.
5.
A simple solution would be to write your own function that also recognizes empty tokens. It could look like this:
C++
CString MyTokenize(CString& source, const LPCWSTR& delimeter, int& first)
{
    CString token;
    int count, end = source.Find(delimeter, first);

    if (end != -1) {
        count = end - first;
        token = source.Mid(first, count);
        first = end + 1; // next token
    }
    else {
        count = source.GetLength() - first;
        token = source.Mid(first, count);
        first = -1;    // last token
    }
    return token;
}
 
Share this answer
 
Comments
CPallini 24-Feb-24 4:27am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900