| | |
Search a string of ','
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2007
Posts: 2
Reputation:
Solved Threads: 0
Title should read "search a string for ',' "
Afternoon folks. I visit this site a bit, especially when searching google for help on a particular problem. This is my first post, so let me get right to the point.
I won't go into the gory details of the program, only what I think is relevant. I'm working with date strings which will be read into the program in two formats:
"November 29, 2005"
or
"11 29 2005"
What I am attempting to do, but can't figure out, is set up an if/else control. Here is the psuedocode of what I'm trying:
So basically, I need to search the string for a comma, and if it finds one, process it with the following, else, do something else.
I know this isn't highly technical. I figured psuedocode would accomplish what I'm seeking.
Thanks in advance!
Val
Afternoon folks. I visit this site a bit, especially when searching google for help on a particular problem. This is my first post, so let me get right to the point.
I won't go into the gory details of the program, only what I think is relevant. I'm working with date strings which will be read into the program in two formats:
"November 29, 2005"
or
"11 29 2005"
What I am attempting to do, but can't figure out, is set up an if/else control. Here is the psuedocode of what I'm trying:
C++ Syntax (Toggle Plain Text)
if (string contains a ',') //do this else //string contains no ',' //do this
I know this isn't highly technical. I figured psuedocode would accomplish what I'm seeking.
Thanks in advance!
Val
Last edited by Valadair; Mar 9th, 2007 at 6:53 pm. Reason: Title should read "Search a string for ',' "
•
•
Join Date: Oct 2006
Posts: 12
Reputation:
Solved Threads: 0
im not sure what are you looking for, but thats a function that checks string for a char and returns true or false; also it returns position of as a ref parameter.
c Syntax (Toggle Plain Text)
#include <string.h> #include <iostream> using namespace std; bool FindS (string strMain, string strWord, int &pos){ if (strMain.find(strWord) == 'npos'){ //not found return (false); } else{ //found pos = strMain.find(strWord); //position return (true); } }
Tell me how the function you just posted would help make your code any simpler.
Plus you need to change 'npos' to string::npos if you want to have any chance of making it work.
Plus you need to change 'npos' to string::npos if you want to have any chance of making it work.
Last edited by John A; Mar 12th, 2007 at 11:12 pm.
"Technological progress is like an axe in the hands of a pathological criminal."
•
•
Join Date: Mar 2007
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
>I figured psuedocode would accomplish what I'm seeking.
You didn't specify if this is to be in C or C++. In C, look for the strchr function. In C++, look for the find_first_of member function of the string type.
C++ Syntax (Toggle Plain Text)
if (dateStr.find(',') != string::npos)
Of course, there is more to the whole idea than that, but that's what I used in the control statement.
Thanks for pointing me in the right direction.
Thanks,
Val
![]() |
Similar Threads
- Search for a string in a variable--- (PHP)
- How to search for a string in a file (C#)
- Search string in a text file (C)
- New User (C)
- Need help with string loop (C)
- "String class" (Java)
- Return Length of a string? (C++)
Other Threads in the C++ Forum
- Previous Thread: Tic Tac Mess
- Next Thread: HELP ME plsssssss AT ROUND ROBIN c++
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






