Greetings,
I have a file that I have written some data into it in the following
manner:
Charlene1719056 :2011392059"1.9 08.555.1212"070 83
The data is arranged in this order:
name, size,Unique key,phone number, zip code
There may be hundreds of these entries in the file. I would like to
parse through it and collect this infor and assigne each value to a
variable, which I can later insert into a database.
I count the number of entries at the begining of the read and know how
many records that I need to parse through. I am having difficulties
parsing through the semicolon and the two brackets to gram what is in
between and after.
Any assistance would be greatly appreciated.
Thank you and best regards,
Johnny 7 4044
Hi Johnny I have a file that I have written some data into it in the following manner:
Charlene1719056 :2011392059"1.9 08.555.1212"070 83
The data is arranged in this order: name, size,Unique key,phone number, zip code
My first suggestion here is to delimit each field, something like..
Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083
And then seperate each record by a DIFFERENT delimeter. Some people prefer a newline, but you could use spaces or any other such character.
Example:
Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083 Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083
-or-
Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083
Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083
Then you could simply do..
open( file );
read_a_record() ; /* Take each record one at a time. Try looking into strtok() */
-> split_record_up (); /* Take each entry of the record. Try strtok() again */
continue read_a_record() until EOF
close( file );
Hope this helped!
-Elliot :)
---
"One must imagine Sisyphus happy."
Elliot <a_*****@hotpop .com> wrote in message news:<200311151 34601.7bb4bfdf. a_*****@hotpop. com>... Hi Johnny
I have a file that I have written some data into it in the following manner:
Charlene1719056 :2011392059"1.9 08.555.1212"070 83
The data is arranged in this order: name, size,Unique key,phone number, zip code
My first suggestion here is to delimit each field, something like..
Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083
And then seperate each record by a DIFFERENT delimeter. Some people prefer a newline, but you could use spaces or any other such character. Example:
Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083 Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083 -or- Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083 Charlene|171905 6|:2011392059|" 1.908.555.1212" |07083
Then you could simply do..
open( file );
read_a_record() ; /* Take each record one at a time. Try looking into strtok() */ -> split_record_up (); /* Take each entry of the record. Try strtok() again */
continue read_a_record() until EOF
close( file );
Hope this helped!
-Elliot :)
--- "One must imagine Sisyphus happy."
Elliot,
Thank you for your suggestions, however, I have no control over the
structure of the data. i have to deal with it as is and manipulate it
as posted.
Any loop suggestions or string manipulation concept and techniques
would be greatly appreciated.
Thanks,
Johnny
On 15 Nov 2003 21:49:12 -0800 we*****@comcast .net (Johnny Sandaire) wrote: Thank you for your suggestions, however, I have no control over the structure of the data. i have to deal with it as is and manipulate it as posted.
Any loop suggestions or string manipulation concept and techniques would be greatly appreciated.
Thanks,
Johnny
Eek!
Things got a bit tougher, but they shouldn't be too hard.
The only way to get the computer to be able to parse the data would be to make sure the majority of the fields have a DEFINITE LENGTH.
Charlene1719056 :2011392059"1.9 08.555.1212"070 83
name size Unique key phone number zip code
My first logical guess would be to do this..
read the whole string
strrev( string );
zip_code = strrev( read_chars( 5 ) ); /* 07083 */
phone = strrev( read_chars( 16 ) ); /* "1.908.555.1212 " */
key_no = strrev( read_chars( 11 ) ); /* :2011392059 */
size = strrev( read_chars( 7 ) ); /* 1719056 */
name = strrev( read_chars( strlen( string ) - 39 ) ) /* 39 = (5+16+11+7) */
This, of course, would mean that the zip, phone, key, and size would all be the same length. Unfortunately I don't expect that your size field will always be constant - i.e. it won't always be a 7-figure number. In my opinion, I can only see this problem becoming something more technical. If the sizes were all different lengths, you would have to read one digit at a time (as characters!) until you reached a real character (as that would signify the start of the name).
I hope this helps!
-Elliot :)
Elliot <a_*****@hotpop .com> wrote in message news:<200311160 14333.31bea0bf. a_*****@hotpop. com>... On 15 Nov 2003 21:49:12 -0800 we*****@comcast .net (Johnny Sandaire) wrote:
Thank you for your suggestions, however, I have no control over the structure of the data. i have to deal with it as is and manipulate it as posted.
Any loop suggestions or string manipulation concept and techniques would be greatly appreciated.
Thanks,
Johnny Eek! Things got a bit tougher, but they shouldn't be too hard. The only way to get the computer to be able to parse the data would be to make sure the majority of the fields have a DEFINITE LENGTH.
Charlene1719056 :2011392059"1.9 08.555.1212"070 83 name size Unique key phone number zip code
My first logical guess would be to do this.. read the whole string strrev( string ); zip_code = strrev( read_chars( 5 ) ); /* 07083 */ phone = strrev( read_chars( 16 ) ); /* "1.908.555.1212 " */ key_no = strrev( read_chars( 11 ) ); /* :2011392059 */ size = strrev( read_chars( 7 ) ); /* 1719056 */
name = strrev( read_chars( strlen( string ) - 39 ) ) /* 39 = (5+16+11+7) */
This, of course, would mean that the zip, phone, key, and size would
all be the same length. Unfortunately I don't expect that your size
field will always be constant - i.e. it won't always be a 7-figure
number. In my opinion, I can only see this problem becoming something
more technical. If the sizes were all different lengths, you would
have to read one digit at a time (as characters!) until you reached a
real character (as that would signify the start of the name). I hope this helps! -Elliot :)
Elliot,
Thank you for your advice. Since I am not sure on how the string will
change over time, I used the String functions to parse through it
looking for the first instance of " and the last of " etc... Then, I
used a substring function call to grab the data in between. Seems to
be working now.
Thanks,
Johnny
Johnny Sandaire <we*****@comcas t.net> writes I have a file that I have written some data into it in the following manner:
Charlene171905 6:2011392059"1. 908.555.1212"07 083
The data is arranged in this order: name, size,Unique key,phone number, zip code
I'd read this record by record into a char array, and use sscanf to
split it up. Or perhaps read it record by record into a std::string and
use sscanf and the std::string c_str() method.
--
Simon Elliott http://www.ctsn.co.uk/
Simon Elliott <si***@nospam.d emon.co.uk> wrote in message news:<wH******* *******@courtla nds.demon.co.uk >... Johnny Sandaire <we*****@comcas t.net> writesI have a file that I have written some data into it in the following manner:
Charlene171905 6:2011392059"1. 908.555.1212"07 083
The data is arranged in this order: name, size,Unique key,phone number, zip code
I'd read this record by record into a char array, and use sscanf to split it up. Or perhaps read it record by record into a std::string and use sscanf and the std::string c_str() method.
Elliott,
If I have the following:
char ScannedData[256]="proc x86 family 6 model 7 type 3"
How can I use sscanf to grab x86, 6, 7 and 3?
I then want to replace the x with the value that is after family to create 686.
Thanks,
Johnny
Johnny Sandaire wrote: Elliott,
If I have the following:
char ScannedData[256]="proc x86 family 6 model 7 type 3"
How can I use sscanf to grab x86, 6, 7 and 3?
Depends.
Are those texts constant or can they vary? Is the format fixed or is it variable?
I assume the simplest case:
char Filler1[80], Filler2[80], Filler3[80], Filler4[80];
char Proc[80], Family[80], Model[80], Type[80];
sscanf( ScannedData, "%s %s %s %s %s %s %s %s", Filler1, Proc,
Filler2, Family,
Filler3, Model,
Filler4, Type );
I then want to replace the x with the value that is after family to create 686.
So Family is always 1 character?
Proc[0] = Family[0];
Of course, the above would need some error checking, etc.
Additionally: This is just one (simple) way to do it. Since your
requirements may vary, so does the way to solve that thing.
Also: Since this is C++, a swtich from character arrays and sscsanf
to std::string and std::stringstre ams would be a good idea.
--
Karl Heinz Buchegger kb******@gascad .at This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fabian |
last post by:
I want to be able to open a window with an url that has parameters like
so:
<a href="foo.html?xx=5&yy=6&ff=1&level=0">..</a>
And then javascript will enter these paramters as global variables.
However, if one or more of these variables are not set, it should use
default values for these variables, read from the start of the
javascript file. How do I parse and set these variables?
|
by: George |
last post by:
How can I parse an HTML file and collect only that the A tags. I have a
start for the code but an unable to figure out how to finish the code.
HTML_parse gets the data from the URL document. Thanks for the help
def HTML_parse(data):
from HTMLParser import HTMLParser
parser = MyHTMLParser()
parser.feed(data)
|
by: kris.dorey |
last post by:
Hi,
Ive got the following code which seems ok but when the user runs the
function for a second time I get an error message stating that the mdb
is in use by another process. There is still an ldb for the life of the
application even after calling oldebconnection.close and gc.collect.
Any ideas?
|
by: ankitdesai |
last post by:
I would like to parse a couple of tables within an individual player's
SHTML page. For example, I would like to get the "Actual Pitching
Statistics" and the "Translated Pitching Statistics" portions of Babe
Ruth page (http://www.baseballprospectus.com/dt/ruthba01.shtml) and
store that info in a CSV file.
Also, I would like to do this for numerous players whose IDs I have
stored in a text file (e.g.: cobbty01, ruthba01, speaktr01, etc.)....
|
by: Klaus Alexander Seistrup |
last post by:
Hi group,
I am new to xgawk (and seemingly to xml also), and I've been struggling
all afternoon to have xgawk¹ parsing an XHTML file containing a hCard²,
without luck. I wonder if you guys could give me a push...
Let's say I have the following XHTML file:
#v+
| |
by: mailtogops |
last post by:
Hi All,
I am involved in one project which tends to collect news
information published on selected, known web sites inthe format of
HTML, RSS, etc and sortlist them and create a bookmark on our website
for the news content(we will use django for web development). Currently
this project is under heavy development.
I need a help on HTML parser.
|
by: toton |
last post by:
Hi,
I have some ascii files, which are having some formatted text. I want
to read some section only from the total file.
For that what I am doing is indexing the sections (denoted by .START
in the file) with the location.
And for a particular section I parse only that section.
The file is something like,
.... DATAS
|
by: maheshkadam |
last post by:
Hi friends
I am new to perl so please guide me.
I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only.
My requirement is to copy backup log for the specific day (yesterday) and write in other file.
That file will be mailed to admin for ready reference.
So here is some text from that log file
|
by: reddyth |
last post by:
Dear All,
I wanted to parse an XML file and print the element's content.
I have the following code for the same. I have printed the ourput too.
The problem is it is printing unwanted spaces and new lines in the output.
Help me avoid this problem.
use XML::Parser;
my $parser = XML::Parser->new( Handlers => {
Init => \&handle_doc_start,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |