From: Ron Michael Khu <ronkhu@ntsp.nec.co.jp>
To: HIToC <hitoc_mail@yahoo.it>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: String assignement
Date: Wed, 26 Jan 2005 00:23:37 +0800 [thread overview]
Message-ID: <41F67289.8020602@hq.ntsp.nec.co.jp> (raw)
In-Reply-To: <200501251604.42747.hitoc_mail@yahoo.it>
Hi!
I dont know much about c++ but after playing around with ur code,
i discovered that u gave the assign() method a wrong value for the
second parameter...
why dont u try "ed-bg+1" ??
(remove the '-1' if u like)
i think the second parameter is count or len... not the end index
-Ron
HIToC wrote:
>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!
>
>
>
prev parent reply other threads:[~2005-01-25 16:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-25 15:06 String assignement HIToC
2005-01-25 16:23 ` Ron Michael Khu [this message]
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=41F67289.8020602@hq.ntsp.nec.co.jp \
--to=ronkhu@ntsp.nec.co.jp \
--cc=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).