473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Question about find_first_of of the STL string class

I have my source string like this:

As i step thru the debugger, I can't understand why
namePosStart is 2
namePosEnd is 15

I expect:
namePosStart is 9
namePosStart is 11

a line: <TestCase name="testcase1">

Here is my code:

cout << "a line: " << aLine << endl;
string::size_type lastPos = aLine.find_first_of("<TestCase", 0);

if (lastPos != string::npos) {
string::size_type namePosStart = aLine.find_first_of("name=\"",
lastPos);
string::size_type namePosEnd = aLine.find_first_of("\"",
namePosStart + 1);
}

I print out 'aLine' to make sure I get the line correctly:
a line: <TestCase name="testcase1">

I appreciate if anyone can help.

Feb 17 '06 #1
1 1580
* Al************@gmail.com:
I have my source string like this:

As i step thru the debugger, I can't understand why
namePosStart is 2
namePosEnd is 15

I expect:
namePosStart is 9
namePosStart is 11
You mean 10 and 15, respectively.

a line: <TestCase name="testcase1">

Here is my code:

cout << "a line: " << aLine << endl;
string::size_type lastPos = aLine.find_first_of("<TestCase", 0);

if (lastPos != string::npos) {
string::size_type namePosStart = aLine.find_first_of("name=\"",
lastPos);
string::size_type namePosEnd = aLine.find_first_of("\"",
namePosStart + 1);
}

I print out 'aLine' to make sure I get the line correctly:
a line: <TestCase name="testcase1">

I appreciate if anyone can help.


'find_first_of' searches for any element in a specified set (in this
case, a set of characters).

'find' searches for a substring.

Use 'find' instead of 'find_first_of'.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Christopher Benson-Manica | last post by:
Let's say I have a std::string, and I want to replace all the ',' characters with " or ", i.e. "A,B,C" -> "A or B or C". Is the following the best way to do it? int idx; while(...
4
by: Christopher | last post by:
I am using std::string to parse a command given by the user, I don't understand why the following snippet is not working as expected. string buffer, // store commands from...
6
by: JustSomeGuy | last post by:
Getline has a delimiter character parameter that is used to say when input should stop. (std::cin.getline) However what do you do if you have multiple conditions/character on which you wish to...
9
by: Suki | last post by:
Hi all, I'm facing a rather strange design problem. Let me explain it. I'm writing an application, which deals with strings extensively. So decided to write a new string class (CXString say) for...
6
by: ma740988 | last post by:
Oh what fun it is to get acclimated with the various containers and algorithms.. I'm trying to determine if I could use find/find_first_of algorithms to achieve the same object of a for loop when...
5
by: Chris | last post by:
Hey all. Anyone who is familiar with Python programming knows that you can have code like this: list = This code puts all the items processed by the for loop in a list plus 1. Is there a way...
2
by: scottys0 | last post by:
Hi everyboy, I'm working in an IOC-IBM (IBM open class) replamecent library. the code seens confused but , no, isn't. #define INumber long class IString : public std::string { private:...
3
by: Bryan | last post by:
If I have the following string from a huge xml file: std::string s = "<input key1=\"v1\" key2=\"val4\" key3=\"test\" />"; I need to get the values associated with the keys out from this line....
3
by: lovecreatesbea... | last post by:
Can the 3rd and 4th arguments of find_first_of(beg1, end1, beg2, end2) and find_end(beg1, end1, beg2, end2) be the same? I got an invalid iterator on following 2 calls: pos_ic_b =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.