LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2014, 08:37 AM   #1
stockton
Member
 
Registered: Jan 2006
Location: Midrand, Gauteng, South Africa
Distribution: Raspbian, Mint 13, Slackware 14, Debian & Ubuntu
Posts: 105

Rep: Reputation: 2
Question extract data from string sent from Windows


In a C socket program I have created I need to extract data from a string sent from the Windows client. A small example of the string is:-
SRC=”<Terminalname>” DST=”<CISTERMINALNAME>” EXC=”PICOENQ”

What I need to do is use the "field" to the left of the = to identify the variable name and the "field" to the right of the = , ignoring the leading "< and the trailing >" as the value for the aforementioned variable. eg the variable dst to contain the value, the name of the terminal. char *dst="terminalname".

So far my thinking is to use strtok to cycle thru the string using the = as the token. Then look for the space character preceding the left most "field" and strcmp that to names of predefined variables and when one is found extract the value from the right "field" by maybe finding the 1st >" after it and copy that data to aforementioned variable.

Surely there is a better way to do this.
 
Old 04-27-2014, 05:25 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
search for non-whitespace char -> first token
search for = -> end of token
search for " and step one char forward
search for " and back one char
start over for the next pair
you can use string compare to identify known tokens and handle values
(you only need to set a pointer to the beginning of the token/value and set the end of string to \0)
 
  


Reply

Tags
data, extract, string



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to extract only certain part from string? raheel_com88 Linux - Newbie 6 01-03-2013 02:00 AM
how to extract from a string Owais.Ahmad Linux - Newbie 13 07-27-2012 06:13 AM
extract a string within a string using a pattern adshocker Linux - Newbie 1 11-04-2010 10:44 PM
[SOLVED] extract part of string himu3118 Programming 4 05-07-2010 07:13 AM
Extract value from string ewingtux Programming 1 12-27-2008 07:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration