From: HIToC <hitoc_mail@yahoo.it>
To: linux-c-programming@vger.kernel.org
Subject: String assignement
Date: Tue, 25 Jan 2005 16:06:52 +0100 [thread overview]
Message-ID: <200501251604.42747.hitoc_mail@yahoo.it> (raw)
Hello all!
I have a string CMD_LN that may contain a substring within angle brackets.
I would like to assign another string IN_BRACKETS with the substring that is
contained within the angle brackets of CMD_LN if it is present.
I have written this code that should work:
// A_brack.cpp
#include <iostream>
#include <string>
int main(int argc, char* argv[])
{
string cmd_ln, in_brackets;
string::size_type bg, ed;
cmd_ln = "Hello <all>, hello world!\n";
bg = cmd_ln.find('<');
ed = cmd_ln.find('>', bg);
if(bg != ed != string::npos) in_brackets.assign(cmd_ln, bg, ed);
cout <<"Starting string:\t" <<cmd_ln <<'\n'
<<"Angle-brackets string:\t" <<in_brackets <<'\n'
<<"bg:\t" <<bg <<"\ned:\t" <<ed <<'\n'
<<cmd_ln[bg] <<' ' <<cmd_ln[ed] <<'\n';
return 0;
}
The output should be:
Starting string: Hello <all>, hello world!
Angle-brackets string: <all>
bg: 6
ed: 10
< >
But...it is not; this is the output of the program:
Starting string: Hello <all>, hello world!
Angle-brackets string: <all>, hel
bg: 6
ed: 10
< >
Thanks!
--
With regards,
HIToC
hitoc_mail@yahoo.it
next reply other threads:[~2005-01-25 15:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-25 15:06 HIToC [this message]
2005-01-25 16:23 ` String assignement Ron Michael Khu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200501251604.42747.hitoc_mail@yahoo.it \
--to=hitoc_mail@yahoo.it \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).