-
string parsing
forgive me if this is already posted elsewhere, but i don't really know where to look. does anyone know of any online resource that goes over string manipulation in depth (particularly parsing)?.....
(a tiny bit of subject) is there a awk/sed like library for c++?
-
There's an online book on parsing that I've not read. But you can use flex and bison. http://www.gnu.org/software/flex/
http://www.gnu.org/software/bison/bison.html
awk/sed do regular expressions. There are libraries out there that do that such gnu's regex and boost's regular expression library. I don't have any experience using them though.
-
i'll check it out...but i guess i should have specified that i want it to work on windows too...
-
i don't have a compiler handy right now, my workstations in use for the next couple hours, but is this ok?
string s("2+3");
string::size_type = s.find(("-" || "+" || "*" || "/"), 0);
in need to extract the sign and the 'term' (includes / and *) that follows. so i need the index of FIRST operator and the index of NEXT. then copy the substring from FIRST to NEXT into a new string. FIRST = NEXT; repeat until string::npos; is there a way to do this without some serious conditional statements?
-
-
flex and bison are probably overkill for what you are trying to do, but you can use them on windows.
If you just what to determine if a string contains an element, use std::find. For example,
Code:
if (std::find(s.begin(), s.end(), '+') != s.end()) {
}
-
no....i need to find the index of those characters....
s.find_first_of("+-*/") is my solution