473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

parse tilde delimited file

Hello, I need to parse a tilde delimited file and output it to a
tabbed delimited file. Example file example.txt

data1~data2~data3~data4
data5~data6~data7~data8

I need to extract data2, data4, data6 and data8 from the above file
and output it to a file delimited by tabs:

data2 data4 data6 data8

I know how to do the ouput but the parsing I'm not sure about. Thanks
for your help. Monte.
Jul 22 '05 #1
3 2744

"monte" <ol******@yahoo.com> wrote in message
news:ac**************************@posting.google.c om...
Hello, I need to parse a tilde delimited file and output it to a
tabbed delimited file. Example file example.txt

data1~data2~data3~data4
data5~data6~data7~data8

I need to extract data2, data4, data6 and data8 from the above file
and output it to a file delimited by tabs:

data2 data4 data6 data8

I know how to do the ouput but the parsing I'm not sure about. Thanks
for your help. Monte.


Actually you have two sets of delimiters, end of line and ~. So you need two
nested loops, the outer reading lines and the inner reading ~ delimited
text.

How about this (untested)

std::string line;
while (getline(file, line))
{
std::istringstream buffer(line);
std::string data;
while (getine(buffer, data, '~'))
{
// do something with data
}
}

john
Jul 22 '05 #2
> Actually you have two sets of delimiters, end of line and ~. So you
need two
nested loops, the outer reading lines and the inner reading ~ delimited text.


If all what needs to be done is replacing the tilde characters by tab
characters, I would just do that:

| #include <fstream>
| #include <algorithm>
| #include <iterator>
| int main() {
| std::ifstream in("in.file");
| std::ofstream out("out.file");
| std::replace_copy(std::istreambuf_iterator<char>(i n),
| std::istreambuf_iterator<char>(),
| std::ostreambuf_iterator<char>(out),
| '~', '\t');
| }

If speed does matter, you will need a good standard C++ library
implementation for this or you might indeed want to read and
process individual lines. However, 'std::getline()'ing a line and
'std::replace()'ing the tilde characters should do the trick.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

Jul 22 '05 #3
monte wrote:
Hello, I need to parse a tilde delimited file and output it to a
tabbed delimited file. Example file example.txt


Oh, that's right - it's September. How could I have forgotten?

--
Mike Smith
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: MW | last post by:
Dear All Does anyone have a regular expression to parse a comma delimited line with some fields optionally having string delimiters (text qualifiers) I am currently testing with this regular...
46
by: vvk4 | last post by:
I have an excel spreadsheet that I need to parse. I was thinking of saving this as a CSV file. And then reading the file using C. The actual in EXCEL looks like: a,b a"b a","b a,",b In CSV...
0
by: CHristian Niss | last post by:
hi there, in a lot of user controls we are using "~" in server tags to reference objects like images <img src="~/images/something.gif" runat="server" />. with framework 1.0 the tilde got...
9
by: Jared Tullis | last post by:
We have an .NET 1.1 application running on 4 2K3 load balanced servers (using WLBS). IIS has the .NET aspnet_isapi.dll mapped as a wildcard application map. The web.config points *.html to a...
2
by: jbolty | last post by:
There have been a few threads talking about using the tilde ~, to reference the webroot path. My problem though is handling an unexpected tilde in a url. this url: ...
4
by: =?Utf-8?B?QWxm?= | last post by:
Hello all, I am having trouble dealing with ~(tilde) in my .Net 1.1 web application, specially when it comes through the URL. For example, when someone requests the following URL:...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
7
by: lancewassing | last post by:
I'm hoping this question is simple. I am trying to create a login script for my already in place client manage using php. I have created a text file filled with usernames and passwords delimited by...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.