Tuesday, 15 May 2012

Getting a substring between two tags C/C++ -


Hello I am creating a type of parser in C / C ++, it just wants to be able to get a string By using the tag "(" and ")" C / C ++, I know that the argument is like finding the first tag and a number gets up to the next tag, which is every one four Is found in But I argue the argument so that someone could give me at least one function that could help.

EDIT: I think the C / C string functions are not the same, just do C ++.

You seem unsure about the difference between string handling in C and C ++. Want to do your description in such a style-style way.

  zero GetTag (const char * str, char * buffer) {buffer [0] = '\ 0'; Four * y = and buffer [0]; Const char * x = & str [0]; Bool copy = false; While (x! = NULL) {if (* x == '(') copy = true; else if (* x == '' '' '' & amp; Copy) {* y = '\ 0'; Break;} and if (copy) {* y = * x; y ++;} ++ x;}} Alternatively, the method of C ++ std :: string Is safe to use because it is unhappy with pointers, and easy to read and understand.  
  std :: string GetTag (const std :: string and str) {std :: String :: size_type start = str.find ('('); if (start! = Str.npos) {std:: String :: size_type end = str.find (')', start + 1); if (end ! = Str.npos) {++ start; Std :: string :: size_type count = end-start; return str.substr (start, count);}} back "";}    

No comments:

Post a Comment