Site icon Learn C++

Learn About Delimiters (Tokens) in Modern C++ On Windows

Delimiters (token term also used) are characters which separates strings between each of them. For example spaces, comas and other symbols can be used as a delimiter char to separate strings between them . Normaly in C++ strtok() were being used in C++, that is used with chars. In Modern C++, strings are now UnicodeStrings, TStringlists has some property to extract strings. If you are new to UnicodeStrings please check here

Example procedure below shows how to split a UnicodeString to a StringList which has delimited UnicodeStrings

[crayon-6629788c07ba4890643888/]

We can easily use this In C++ Builder. Create a new “Multi-Device C++ Builder Project” , Add a Memo and a Button on the Form of Project. Double click to Button, add this split procedure and OnClick() event of Button as below;

[crayon-6629788c07bac069580327/]

Header of this project will be automatically like this.

[crayon-6629788c07bb1804982730/]

We can use any UnicodeString Chars as given above in L’ ‘ format. This method supports UnicodeStrings, because of this it is much more modern than classic strtok() function. Instead of this split(…) definition, we can also define this function as a member of Form like this;

[crayon-6629788c07bb3257585894/]

This time this split procedure should be defined as a a public member in public: definitions of Form1 class as below;

[crayon-6629788c07bb8954878712/]

Using Delimiters globally in all languages requires to use of UnicodeStrings, and sometimes analyzing these text forms highly needs this kind of new modern methods. We think that this example will help you to analyze Unicode text forms.

Exit mobile version