in MS VC++ Express I need to know how to get from one comma delimited
text string to many strings.
from this:
main_string = "onE,Two,Th ree , fouR,five, six "
to these:
string1 = "one"
string2 = "two"
string3 = "three"
string4 = "four"
string5 = "five"
string6 = "six"
the white space needs to be removed and the case needs to be all upper
or lower.
The result needs to be strings and not pointers or addresses in memory
so I can test:
string test = "three";
if (three == "three")
some getlines will only have two strings some may have up to 10
Please help with examples, you input with exact syntax is greatly
appreciated
I have been struggling with not using pointers but every time I end up
using them.
Thanks in advance
Feb 7 '06
25 31805
Alf P. Steinbach wrote: result[i] = static_cast<cha r>( std::toupper( s[i] ) );
The above line shall read
result[i] = std::toupper( static_cast<uns igned char>(s[i]));
While the compiler automatically takes care of the conversion from
'char' to 'int', it could produce negative values on systems where
'char' is a signed type without the explicit conversion to 'unsigned
char'. However, 'std::toupper(i nt)' only accepts positive values
making it necessary to convert the 'char' to an 'unsigned char'
first.
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
In article <44************ @individual.net >,
Dietmar Kuehl <di***********@ yahoo.com> wrote: Daniel T. wrote: int (*lower)(int) = &tolower; transform( str.begin(), str.end(), str.begin(), lower );
Note that this does *NOT* work! The argument to 'std::tolower() ' has to be an *unsigned* value. However, on platforms where 'char' is signed, the argument could expand to a negative value! In portable code, the only valid call to 'std::tolower(i nt)' with a 'char' looks like this:
std::tolower(st atic_cast<unsig ned char>(c));
The only possible variation is how the 'char' is first cast to an 'unsigned char'.
That is only necessary if one is using an extended character set. For
all ASCII characters, "tolower( c )" will work just fine. In order to
write portable code, one must not use an extended character set, making
the cast will not magically make it portable.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
In article <44************ @individual.net >,
Dietmar Kuehl <di***********@ yahoo.com> wrote: Injecting existing filtering stream buffers into the processing is pretty straight forward. Of course, writing them is not necessarily so but it is not that hard either. The real advantage I see in the filtering stream buffer over your code is that it encapsulates the complete solution, especially if it is also equipped with a simple input stream which automatically maintains the stream buffer.
I read up on streambuf's last night. Although, your solution does work,
I think it is inappropriate. Stream Buffers are supposed to represent
buffering strategies for different kinds of streams, not conversion
strategies.
Both of our codes encapsulated the complete solution.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Daniel T. wrote: I read up on streambuf's last night.
Just out if interest: where did you read up on them?
Although, your solution does work, I think it is inappropriate. Stream Buffers are supposed to represent buffering strategies for different kinds of streams, not conversion strategies.
Stream buffers are intended to represent streams of characters.
When streaming characters, it is quite common to transform them
in some way. Actually, this is the basis of UNIX' approach to
filters. My code effectively just did the moral equivalent of
"tr 'A-Z,' 'a-z '" which is, IMO, an entirely appropriate use
of streams.
In fact, even at the very basis of file streams, (i.e. in the
class template 'std::basic_fil ebuf') a heavy conversion mechanism
is employed which converts bytes read from a file into characters
used within an application or vice versa. This uses 'std::codecvt'
facets and it would be an easy typing exercise to inject the
conversion I implemented in the stream buffer into a corresponding
facet.
Both of our codes encapsulated the complete solution.
Well, I somewhat disagree with this statement but then, the
problem was trivial enough that it may not be worth to encapsulate
the solution further than you did.
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Daniel T. wrote: That is only necessary if one is using an extended character set. For all ASCII characters, "tolower( c )" will work just fine. In order to write portable code, one must not use an extended character set, making the cast will not magically make it portable.
As far as I know, standard C++ does not privilege the ascii charset in any
way, nor any other 0-127 charset.
Of course you have less problems if you know for sure that all your users
use ascii. But you will also have less users.
--
Salu2
* Dietmar Kuehl: Alf P. Steinbach wrote: result[i] = static_cast<cha r>( std::toupper( s[i] ) ); The above line shall read
result[i] = std::toupper( static_cast<uns igned char>(s[i]));
Thanks for that correction, it was a screw-up.
While the compiler automatically takes care of the conversion from 'char' to 'int', it could produce negative values on systems where 'char' is a signed type without the explicit conversion to 'unsigned char'. However, 'std::toupper(i nt)' only accepts positive values
And EOF. ;-)
making it necessary to convert the 'char' to an 'unsigned char' first.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Arne |
last post by:
From: "Arne de Booij" <a_de_booij@hotmail.com>
Subject: Comma delimited array into DB problems
Date: 9. februar 2004 10:39
Hi,
I have an asp page that takes input from a form on the previous page,
puts that into an array and inserts the array into SQL server.
Now here is the problem:
|
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 expression and it works in almost
all my test cases. I found this on the internet in a C# solution.
,(?=(*"*")*(?!*"))
However in some of my test cases it fails and I am having difficulty
|
by: Ram Laxman |
last post by:
Hi all,
I have a text file which have data in CSV format.
"empno","phonenumber","wardnumber"
12345,2234353,1000202
12326,2243653,1000098
Iam a beginner of C/C++ programming.
I don't know how to tokenize the comma separated values.I used strtok
function reading line by line using fgets.but it gives some weird
behavior.It doesnot stripout the "" fully.Could any body have sample
code for the same so that it will be helfful for my...
|
by: Larry Williams |
last post by:
Is there an easy way to convert a string of data to XML format without having
to create the xml one field at a time?
Sorry I'm a newbie and my xml knowledge is limited. I have tried to search
through the documentation in .net but nothing jumps out at me.
Sample code would be great!
|
by: Wayne |
last post by:
I have the following string:
"smith", "Joe", "West Palm Beach, Fl."
I need to split this string based on the commas, but as you see the city
state contains a comma. String.split will spilt the city state. Is there a
built in function that I'm missing that will do the split and recognize that
the comma in city state is part of the item?
--
| |
by: Yama |
last post by:
Hi,
I am looking to create a report comma delimited on a click of a button.
Explanantion:
1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'"
2. Use either DataReader or DataSource
3. Create a button "Export"
4. On ServerClick Event prompt user to save as a text comma delimited file.
|
by: Ron |
last post by:
so if my textbox is named textbox1 and my listbox is named
ltsdisplay, for the button that would make this all happen I would
just need to:
lstdisplay.items.textbox1(delimited.Split(",".ToCharArray()))
is that right? or no? I try this and I get an error...
|
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
|
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts, disregarding the syntax that stream contains. Parsing is actually including the syntax in order to make...
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |