473,698 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

36 New Member
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 2171
weaknessforcats
9,208 Recognized Expert Moderator Expert
You can use string::rfind() . It searches the string in reverse order.
Jul 1 '07 #2
Soneji
36 New Member
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
1917
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 distance. Where can I find software that find the ground distance (like in Mapquest). Thanks, Joe
4
26396
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
2076
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: 'tblContact' and 'tblCategory' where categories are like: Code Name 010101 Short 010102 Fat
1
3968
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> <SpecificInformation>
2
2213
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 "CHARS 'TO' - found 239 times within columns 48 to 56". Please guide me as to how to make this PDS back to normal so that the FIND command processes the whole 1 TO 80. Thank you for the valuable time.
5
2574
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 it returns the iterator to the last element in the range, not to the last element in the container, to the last element in the range. That being said, how can we tell if find() has been successful in finding the element we need? Its easy when we...
2
1611
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? Thanks, David
8
8646
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
2154
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() that has _MyValue = unitialized memory (it appears). Thus, the returned iterator is garbage and an exception is thrown eventually. I thought that find() returned the location succeeding the last element in the map if a match was not found. It seems...
4
5530
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 match on doubles? second: if yes, how may this be done (i.e. how many one specify the tolerance threshold for comparing doubles?)
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.