Solved

parse

Posted on 2012-04-11
2
246 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now