Hey,
I am working on this project where I am storing info from status messages in a vector. Once elements are stored I am reading the vector and displaying them in a list ctrl. However, if the element contains a time the element needs to be diplayed in the first column(which is Time). So I am trying to check to see if the element is in the following format"hh:mm:ss", if so it is a time value. Well, I have searched and have not found anything that allows me to do this. By any chance is there a way to do this. Any help will be greatly appreciated.
You could test it step by step. First check the length == 8 characters.
Next check the existence of the colon ':' at positions 2 and 5.
If the above is true, it's already quite probable that you have a time element. But you could finish the checking by verifying that the other characters are all numeric digits, maybe by using isdigit() http://www.cplusplus.com/reference/cctype/isdigit/
Chervil,
Thanks. I fully understand what you are saying but I am having a hard time to figure out how to do this with vectores. This is my first time working with vectors. This is what I have tried but failed:
1 2 3 4 5 6 7 8 9 10
for(vector<CString>::iterator it = myvector.begin(); it != myvector.end(); it++)
{
//Trying to check lenght for each element in vector
if(myvector[it].GetLength==8)
{
// do checks
}
}
In the code above I get build errors about using GetLength. I am not sure how to retrieve each element and perfrom the checks you mentioned.
#include <iostream>
#include <vector>
int main(){
std::vector<std::string> date = {"3",":","3",":","03"};
/*to access elements -->(date[0] == '3') .. (date[1] == ':') .. (date[2] == '3') .. (date[3] == ':')
and (date[4] == "03")
*/
date[4] = "05";
/* i just checked and this works to.. */
date[4][0] = '4';
//soo in c++11 this will output the vector...
for(auto i: date) std::cout<<i;
}
if you can use c++11, compile with (-std=c++11 with g++), if not this won't work..
Chervil,
Thanks for the above input. The GetLength() is working, but checking everything else isn't. For example if I have a vector with an element equal to,"10:25:34". I am having a problem with checking to see if that element is in the following format hh:mm:ss. I can't check the index because, well I don't think I can because it is all one element. Just checking to see if the length is 8 isn't going to do because a status can be just a length of 8. Any help will be greatly appreiated. Thanks In Advance.
Chervil,
Thanks. I am now able to check for ':' by using GetAt() or *it[index], but am having problems with checking to see if other indexs is a digit.
I have used the following to check to see if it is a digit:
1 2 3 4 5 6
if(isdigit(it->GetAt(2))
{
//do something
}
1 2 3 4 5 6 7
if((*it)[2] == ':')
{
//do something
}
I am not getting errors but my check is not true which it should be.Any help will be greatly appreiated. Thanks In Advance.