Solved

parse

Posted on 2012-04-11
2
250 Views
Last Modified: 2012-04-11
Hi is it possible to use strtok to parse some data using a string as the first deliminator rather than using punctuation?


for example

data here string a b c d
more data here to disregard string e f g h

so that I only get a b c d e f g h?

Thanks
0
Comment
Question by:codey-06
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 37835142
You can't do that with 'strtok()', since it uses single characters as delimiters, but 'strstr()' can help you here:

const char* get_text_afer_delimiter(cconst char* in, const char* delim) {

  char* p = strstr(in,delim);

  if (!p) return NULL; // 'delim' not found

  return p + strlen(delim);
}

// ...

char* p1 = "data here string a b c d";
char* p2 = "more data here to disregard string e f g h";

const char* p3 = get_text_afer_delimiter(p1, "string "); // include the blank, so the returned pointer points directly to "a b c d"

const char* p4 = get_text_afer_delimiter(p2, "string "); // include the blank, so the returned pointer points directly to "e f g h"

Open in new window

0
 

Author Closing Comment

by:codey-06
ID: 37835234
Thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question