I want to know how to validate a string which is comma separated
"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
I need to validate each field value against a set of rules, for example
checking if the string is a character or a numeric value, for the
length of the character etc. 10 2691
Nishanth wrote:
I want to know how to validate a string which is comma separated
"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
I need to validate each field value against a set of rules, for example
checking if the string is a character or a numeric value, for the
length of the character etc.
Separate the string into the fields, and then compare each subfield
against the validation criteria. The remainder is left as an exercise
for the reader.
Hi Red,
Can you be more specific. as i am a newbie to c++ programming.
How do I separate the string into the fields? and how do I validate
each of them?
If you can help me out with some example programmes or some websites
which help out begginners with this it will be quite help full.
Thanks,
Nishanth
red floyd wrote:
Nishanth wrote:
I want to know how to validate a string which is comma separated
"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
I need to validate each field value against a set of rules, for example
checking if the string is a character or a numeric value, for the
length of the character etc.
Separate the string into the fields, and then compare each subfield
against the validation criteria. The remainder is left as an exercise
for the reader.
Hi Red,
Can you be more specific. as i am a newbie to c++ programming.
How do I separate the string into the fields? and how do I validate
each of them?
If you can help me out with some example programmes or some websites
which help out begginners with this it will be quite help full.
Thanks,
Nishanth
red floyd wrote:
Nishanth wrote:
I want to know how to validate a string which is comma separated
"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
I need to validate each field value against a set of rules, for example
checking if the string is a character or a numeric value, for the
length of the character etc.
Separate the string into the fields, and then compare each subfield
against the validation criteria. The remainder is left as an exercise
for the reader.
Nishanth wrote:
Hi Red,
Can you be more specific. as i am a newbie to c++ programming.
How do I separate the string into the fields? and how do I validate
each of them?
If you can help me out with some example programmes or some websites
which help out begginners with this it will be quite help full.
Hint :- Tokenize the source string by using ',' as token.
~Madhav
"Nishanth" <ra**********@g mail.comwrote:
I want to know how to validate a string which is comma separated
"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
I need to validate each field value against a set of rules, for example
checking if the string is a character or a numeric value, for the
length of the character etc.
I'd recommend, first put your string in a std::string, so you
get all its cool member functions. (Research "std::strin g".)
Then, make a class with data members to hold your fields and a
parameterized constructor to parse the input string into its
fields and store the fields in the members.
I'm guessing from looking at your sample string that you're not
allowing any embedded spaces in your fields? If so, that
makes things simple, because you can just convert all the quote
marks and commas into spaces, then use a stringstream and the
">>" operator to dump the fields into your members.
Something like this should work for you:
#include <iostream>
#include <string>
#include <sstream>
using std::cout;
using std::endl;
class Dossier
{
public:
// parameterized constructor:
Dossier(std::st ring InputString);
// declare validation functions here
// declare any other methods you need here
// You might want to consider making these private,
// but I'm leaving them public for now, for simplicity:
std::string code;
std::string number;
std::string zip;
std::string title;
std::string first_name;
std::string last_name;
std::string dob;
};
Dossier::Dossie r(std::string InputString)
{
std::replace(In putString.begin (), InputString.end (), '\"', ' ');
std::replace(In putString.begin (), InputString.end (), ',' , ' ');
std::istringstr eam SS(InputString) ;
SS >code >number >zip >title >first_name >last_name >dob;
}
int main()
{
std::string argle =
"\"C1\",\"2\",\ "12344\",\"Mr\" ,\"John\",\"Cha n\",\"05/07/1976\"";
Dossier d(argle);
cout
<< d.code << endl
<< d.number << endl
<< d.zip << endl
<< d.title << endl
<< d.first_name << endl
<< d.last_name << endl
<< d.dob << endl;
return 0;
}
It should be a simple matter to add whatever validation
functions you want, as member functions of your class.
--
Cheers,
Robbie Hatley
Tustin, CA, USA
lonewolfintj at pacbell dot net
(put "[usenet]" in subject to bypass spam filter) http://home.pacbell.net/earnur/
Robbie,
I copied the above said programme and tried running it in VC++, I got
an error as
'replace' : is not a member of 'std' & 'replace' : undeclared
identifier.
I have not made any changes to the code.
Please help.
Thanking you,
Nishanth
Nishanth skrev:
Robbie,
I copied the above said programme and tried running it in VC++, I got
an error as
'replace' : is not a member of 'std' & 'replace' : undeclared
identifier.
I have not made any changes to the code.
Please help.
#include <algorithm>
--
TB @ SWEDEN
"Nishanth" writes:
I copied the above said programme and tried running it in VC++, I got
an error as
'replace' : is not a member of 'std' & 'replace' : undeclared
identifier.
I have not made any changes to the code.
You are expected to learn something from this process. Look in your
reference material and see if Robbie misspelled "replace" or something such
as that. You should start building up some resources to supplement your
text book. For example: http://www.dinkum.com/manuals/?manua...=algorith.html
shows that there is, indeed such a function. And that its prototype is in
<algorithms>. But Robbie simply forgot to include that header. Now try to
fix things up. Keep the above link where you can find it again. Don't be
shy about address pruning. If you don't know what pruning is, find out.
"Nishanth" <ra**********@g mail.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
>I want to know how to validate a string which is comma separated
"C1","2","12344 ","Mr","John"," Chan","05/07/1976".........
I need to validate each field value against a set of rules, for example
checking if the string is a character or a numeric value, for the
length of the character etc.
This is called "Comma Separated Variables" or CSV. The easiest solution,
download the CSVParser class (google for it). It does not have every
possible variable type defined in it (such as your date) but you can add
those fairly easily.
If this is homework, however, you'll need to write your own parser. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Craig Keightley |
last post by:
is it possible to compare acomma separated list aginst another
eg comma list 1 => 1,2,3,4,5
comma list 2 => 3,5
can you check that 3 is in both, and 5 is in both, therfore they match???
the comparison is to check that if product a who supplies products 1,2,3,4,5
can be used instead of product b who supplies 3,5 as product a already
supplies them
|
by: Craig Keightley |
last post by:
I can do the match perfectly but what i also need to do is create a third
list of comma separated values that are in both
eg:
List 1 => 1,2,3,4,5,6,7,8,11
List 2 => 1,3,4,5,6,7,10,23
Therefore
|
by: Christina |
last post by:
I have a post-form that holds a listbox with mulitple selected items. When
the form is posted to the server ASP file, I want to loop through the
selected items, to insert each of them into a table. How do I do that?
If I execute the line:
Response.Write(Request.Form("ListBox")),
I get the list of selected values, separated by commas.
Christina
|
by: Rahul Chatterjee |
last post by:
Hello All
I am uploading a file using ASP code. After the user uploads the file, I
would like to be able to open the file and check if the data is in a given
format (comma separated) and also has all the data elements needed (i.e. all
fields are there). Is there a parse routine in asp that would allow me to do
this. The user can upload any type of file as long as I am able to parse it
and determine if the data is of the aforemention...
|
by: Craig Keightley |
last post by:
I have a mysql database with a list of companies who supply specific
products
tblSuppliers (simplified)
sID | sName | goodsRefs
1 | comp name | 1,2,3,4,5
2 | company 2 | 2,4
| |
by: ani |
last post by:
I have two submit buttons in my form which need to
validate two different controls on the page . How do I
validate portions of the asp.net page. The two submit
buttons should validate their respective controls. If
anyone has got any articles or sample pages, please
forward..
Thanks..
|
by: mac |
last post by:
Hi,
I'm trying to write a fibonacci recursive function that will return
the fibonacci string separated by comma. The problem sounds like this:
-------------
Write a recursive function that creates a character string containing
the first n Fibonacci numbers - F(n) = F(n - 1) + F(n - 2), F(0) =
F(1) = 1 -, separated by comma. n should be given as an argument to
the program. The recursive function should only take one parameter, n,
and...
|
by: mac |
last post by:
Hi,
I'm trying to write a fibonacci recursive function that will return
the fibonacci string separated by comma. The problem sounds like this:
-------------
Write a recursive function that creates a character string containing
the first n Fibonacci numbers - F(n) = F(n - 1) + F(n - 2), F(0) =
F(1) = 1 -, separated by comma. n should be given as an argument to
the program. The recursive function should only take one parameter, n,
and...
|
by: sufian |
last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message:
echo("<div id=\"message\" class=\"success\">Thank you! You have been successfully registered.</div>");
within 1.5 seconds.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta...
|
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: 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: 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: 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...
| |