473,388 Members | 1,600 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,388 software developers and data experts.

Function to search for Characters

So.. I am new in C++.. just wanted to know if someone can help me doind
a function to check if there is a character in a string.. for example

string ex
ex << hello 33

if(there is 33 in strin ex)
- do wateva -

if(there is hello in string ex)
- do wateva-

if(!there is A in string ex)
- do wateva -

Thanks in advance,
Thiago

Jan 17 '06 #1
3 1587
On 17 Jan 2006 03:59:47 -0800, th*******@gmail.com wrote:
So.. I am new in C++.. just wanted to know if someone can help me doind
a function to check if there is a character in a string.. for example

string ex
ex << hello 33

if(there is 33 in strin ex)
- do wateva -

if(there is hello in string ex)
- do wateva-

if(!there is A in string ex)
- do wateva -

Thanks in advance,
Thiago


std::string.find() is your friend.

FAQ: http://www.parashift.com/c++-faq-lite/

--
Bob Hairgrove
No**********@Home.com
Jan 17 '06 #2
th*******@gmail.com wrote:
So.. I am new in C++.. just wanted to know if someone can help me doind
a function to check if there is a character in a string.. for example

string ex
ex << hello 33

if(there is 33 in strin ex)
- do wateva -

if(there is hello in string ex)
- do wateva-

if(!there is A in string ex)
- do wateva -


#include <string>
#include <iostream>

int main()
{
std::string ex("hello 33");

if (ex.find("33") != std::string::npos)
std::cout << "There is 33 in the string\n";

if (ex.find("hello") != std::string::npos)
std::cout << "There is hello in the string\n";

if (ex.find("A") == std::string::npos)
std::cout << "There is no A in the string\n";
}
Jan 17 '06 #3
On Tue, 17 Jan 2006 13:09:27 +0100 in comp.lang.c++, Rolf Magnus
<ra******@t-online.de> wrote,
int main()
{
std::string ex("hello 33");

if (ex.find("33") != std::string::npos)
std::cout << "There is 33 in the string\n";


You get an "A"

Jan 18 '06 #4

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

Similar topics

5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
1
by: Robert | last post by:
Vb.Net Make dll that contain one function. Help Please. I would like to call a function from different applications. I think i have to make a dll. I have Visual Basic.net 2003 Standard...
8
by: ais523 | last post by:
I use this function that I wrote for inputting strings. It's meant to return a pointer to mallocated memory holding one input string, or 0 on error. (Personally, I prefer to use 0 to NULL when...
5
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word...
0
by: Luis Corrales | last post by:
Hi all, I have a problem when searching for text with special characters in e-mails in an IMAP server. I'm using imaplib in python 2.4.3 and I can't get this code working: # first connect and...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
2
by: .Net Sports | last post by:
I posed this problem last month here, but need more of a clarification, as I still cannot correctly flag a bad password. I need users to submit a passowrd that has at least one numeric character,...
3
by: Paddy | last post by:
Lets say i have a generator running that generates successive characters of a 'string' characters then I would have to 'freeze' the generator and pass the characters so far to re.search. It is...
2
by: parasuram | last post by:
Hi friends ............. this is a question regarding the data structures trees Pleas post it if possible with in 2 days I will thankful if some body could help doing this. Operating...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
jinu1996
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...

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.