473,386 Members | 1,745 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,386 software developers and data experts.

Give me that second substring! A string::find() production.

36
Just a quickie today...

Is there another ( better ) way to get the second value from this string::find example:

Expand|Select|Wrap|Line Numbers
  1.   std::string str( "More strings of the string variety" );
  2.   size_t loc;
  3.  
  4.   loc = str.find( "string" );
  5.   loc = str.find( "string", loc + 1, 6 );
  6.  
  7.   std::cout << "Location of second string: " << loc << '\n';
  8.  
I'm working in the wonderful world of 'strings', and I ran into 'find'...

Now, if the "strings" were reversed:
Expand|Select|Wrap|Line Numbers
  1.  
  2.   std::string str( "My string is better than other strings." );
  3.   size_t loc;
  4.  
  5.   loc = str.find( "strings", 0, 7 );
  6.  
  7.   std::cout << "Location of second string: " << loc << '\n';
  8.  
This would work wonderfully.

I happened to run into this situation, and I thought, "Hey!" Maybe someone
at theScripts has a better way of doing this.

Thanks for your time.

Lates!

-Soneji
Jul 1 '07 #1
2 2148
weaknessforcats
9,208 Expert Mod 8TB
You can use string::rfind(). It searches the string in reverse order.
Jul 1 '07 #2
Soneji
36
D'oh!

Now why didn't I know that? :P

Thank you!! I should have thought about that... *Sigh*

Oh, BTW.... Check the other post we looked into:

Post of the mighty!

Lates!

-Soneji
Jul 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Galsaba | last post by:
I am trying to find a software that can find distance between two ZIP codes. I think most of them do it by having the longtitude and latidute of each ZIP, and substract. But this gives the air...
4
by: Matthias Hildebrand | last post by:
Hello, std::map< int, MyClass*> mymap; it = mymap.find( somekey ) // here happen bad things if( it != mymap.end() ) { // do something useful with it->second } else
16
by: Justin Hoffman | last post by:
This is a question concerning query optimisation. Sorry if it's a bit long, but thanks to anyone who has the patience to help - This is my first post here... If I have two tables:...
1
by: mirandacascade | last post by:
I do not understand how to use the find() method in ElementTree. The file 'sample.xml' is: <?xml version="1.0"?> <SampleRoot> <Header> <Product>FindMystery</Product> </Header>...
2
by: Praveen | last post by:
In the ISPF editor I am using, for a particullar PO Dataset I am getting the result of FIND statement narrowed down to the colums 48-56. i.e. if I give "FIND 'TO' ALL", the result I am getting as...
5
by: Draw | last post by:
Hi All, Just a thought, about the find() algorithm in the C++ STL. I read that the find algorithm can take a range of iterators. If it does not find the element it is looking for in that range...
2
by: David | last post by:
We're using Access 2003 as a front end for a SQL Server database. When opening a linked table in Access, why is there such a huge speed difference in Filtering by a value and doing an Edit->Find?...
8
by: brekehan | last post by:
If I have a class MyClass { ...bunch o data and methods int x; }; and a stl container of MyClass objects Is there a way to use std::find to get all the elements whose member x
2
by: cyndykoobs | last post by:
I have run into a problem that I cannot seem to figure out regarding a method call to STL map::find(). When the key value can't be found in the map (this is an expected scenario), it returns end()...
4
by: Anonymous | last post by:
I ahve a vector of doubles taht I need to extract values from. I was just about to use the STL find() algo, but I have a couple of questions: first: can you specify the tolerance threshold to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.