Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

parse

Posted on 2012-04-11
2
Medium Priority
?
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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