Parse (split) a string in C++ using string delimiter (standard C++)

You can use the std::string::find() function to find the position of your string delimiter, then use std::string::substr() to get a token. Example: The find(const string& str, size_t pos = 0) function returns the position of the first occurrence of str in the string, or npos if the string is not found. The substr(size_t pos = 0, size_t n = npos) function returns a substring of the object, … Read more

How can I split and parse a string in Python?

“2.7.0_bf4fda703454”.split(“_”) gives a list of strings: This splits the string at every underscore. If you want it to stop after the first split, use “2.7.0_bf4fda703454”.split(“_”, 1). If you know for a fact that the string contains an underscore, you can even unpack the LHS and RHS into separate variables: An alternative is to use partition(). … Read more

What is parsing?

Parsing usually applies to text – the act of reading text and converting it into a more useful in-memory format, “understanding” what it means to some extent. So for example, an XML parser will take the sequence of characters (or bytes) and convert them into elements, attributes etc. In some cases (particularly compilers) there’s a … Read more

What is a Context Free Grammar?

A context free grammar is a grammar which satisfies certain properties. In computer science, grammars describe languages; specifically, they describe formal languages. A formal language is just a set (mathematical term for a collection of objects) of strings (sequences of symbols… very similar to the programming usage of the word “string”). A simple example of … Read more