C++ checking elements of strings for equality [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
given a string in this format:
07:05:45PM
I am to convert it to military time.
My idea is to check element 8 of the string for whether it is a 'P' or an 'A' and modify the string accordingly however this expression:
if (time[8] == 'P' );
always evaluates as true whether time[8] is an 'A' or a 'P' or even a '7'
why?

Because you have an extra semicolon, right after the if statement.

Related

why does [[:xdigit:]] highlight letter e in grep results? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Why does below command highlight e as well with digits?
grep '[[:xdigit:]]' search.txt
This is intended, as it searches for hexadecimal digits.
The man-page states:

Ereasing a particular char from whole std::string [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I wanted to clear string from unwanted chars, and I tried to iterate it through a loop like this.
for(auto it=numer.begin(); it!=numer.end(); ++it)
{
if(*it=='-') numer.erase(it);
}
The error is: "expected primary-expression before '=' token";
I could, of course, I could do this with [] operator. But I am wondering why it doesn't work.
I appreciate your help.
If you want to remove all instances of a character from a string, a simple way to do that would be to use the standard erase-remove(if) idiom:
numer.erase(std::remove(numer.begin(), numer.end(), '-'), numer.end());
See also:
https://en.cppreference.com/w/cpp/string/basic_string/erase
https://en.cppreference.com/w/cpp/algorithm/remove

capture numbers between two characters in R [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I need to capture cpu usage data from this string, in this cast cpu usage is 1.55. Values between - and %
cpu<-c("CPU Usage: u814.13 s13.33 cu0 cs0 - 1.55% CPU load")
I have tried this:
as.numeric(gsub("^.*- ([0-9]+).*$", "\\1", cpu))
It is giving 1.
Any ideas what I'm doing wrong here?
([\d\.]+)% CPU.*$
You didn't include the decimal dot in the square brackets

C++ character check [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have just started to learn C++ and i would like to get some help.
The user needs to type an ID number and the format has to be the following. The first character B and the other 4 any integer.
Im trying to check if the character format are right.
So far i have this:
if ((isalpha(id[0])=='B' ) && (isdigit(id.at(1))) && (isdigit(id.at(2))) ......
{
//do something
}
else
{
cout << "Wrong format" << endl;
}
but even if i type example B8745 it says wrong format.
You are comparing the result of isalpha, which is boolean, to character literal 'B'.

Notepad++ and regex [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am doing some test with Find in Notepad++ using regex. Here is my problem that I can't figure out why:
My text is:
abc/xyz/p234/s-sdf
The following regex matches well:
[a-z]+/[a-z]+(/p[0-9]+)/s-[a-z]+
But why the following regex (with an added '?') does not match anymore:
[a-z]+/[a-z]+(/p[0-9]+)?/s-[a-z]+
Am I right that in the last regex, the '?' means that (/p[0-9]+) can appear zero or one time?