Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Problem using Split on carriage return
Re: Problem using Split on carriage return [message #10469 is a reply to message #10467] Tue, 10 July 2007 23:26 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14266
Registered: November 2005
Ultimate Member
Well, it is not U++, it is M$... Back in MSDOS days, they have decided that line are to be ended with "\r\n" and this stupid idea is still alive.

Standard C library solves this problem by intruducing "text" and "binary" streams (text streams remove/insert \r on read/write), but IMO that just adds to confusion.

U++ general take on the problem is to ignore all \r characters on input and insert \r before each \n on output - but both is to be handled by the code.

In your case you have many options. One simple is to filter out all \r out before Split:

int NoCr(int c) { return c == '\r' ? 0 : c; }

Split(Filter(s, NoCr), '\n')


As you seem to ignore empty lines, another simple solution (with a bit better performance) is to treat \r like \n (because it will just result in empty line, which is ignored anyway):

int CrOrLf(int c) { return c == '\r' || c == '\n' ? c : 0; }

Split(s, CrOrLf);


Mirek
[/code]
 
Read Message
Read Message
Read Message
Previous Topic: Gate() or flow control problem
Next Topic: How to do interation on Vector<String>
Goto Forum:
  


Current Time: Fri Jul 18 03:36:49 CEST 2025

Total time taken to generate the page: 0.03943 seconds