473,498 Members | 891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String Manipulation doubt

I have two strings as below

string A = "102030405060.wldep.1251.jpg";
string B= "102030405060.wldep.1251.pdf";

I want the word after last dot in other two strings
i.e;
string C = "jpg";
string D="pdf";

Early code help is greatly appreciated.

regards

Jango

Feb 2 '06 #1
5 1577
noopathan wrote:
I have two strings as below

string A = "102030405060.wldep.1251.jpg";
string B= "102030405060.wldep.1251.pdf";

I want the word after last dot in other two strings
i.e;
string C = "jpg";
string D="pdf";


Try

std::find_last_of

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 2 '06 #2
noopathan wrote:
I have two strings as below

string A = "102030405060.wldep.1251.jpg";
string B= "102030405060.wldep.1251.pdf";

I want the word after last dot in other two strings
i.e;
string C = "jpg";
string D="pdf";

Early code help is greatly appreciated.

regards

Jango


Use std::string::rfind.

Regards, Stephan

Feb 2 '06 #3
In article <11*********************@g47g2000cwa.googlegroups. com>,
"noopathan" <ms*****@gmail.com> wrote:
I have two strings as below

string A = "102030405060.wldep.1251.jpg";
string B= "102030405060.wldep.1251.pdf";

I want the word after last dot in other two strings
i.e;
string C = "jpg";
string D="pdf";

Early code help is greatly appreciated.

regards

Jango


assert( A.rfind('.') != string::npos );
string C = A.substr( A.rfind('.') + 1 );
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 2 '06 #4

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
In article <11*********************@g47g2000cwa.googlegroups. com>,
"noopathan" <ms*****@gmail.com> wrote:
I have two strings as below

string A = "102030405060.wldep.1251.jpg";
string B= "102030405060.wldep.1251.pdf";

I want the word after last dot in other two strings
i.e;
string C = "jpg";
string D="pdf";

Early code help is greatly appreciated.

regards

Jango


assert( A.rfind('.') != string::npos );
string C = A.substr( A.rfind('.') + 1 );


Don't use assert for something like this you want to put into production.
Once you turn off debug mode asserts disappear. So it would totally ignore
that. I would rather do:

std::string C;
if ( A.rfind('.') != string::npos )
C = A.substr( A.rfind('.') + 1 );

That'll work in production or debug. Yes, it assigns a null string and
doesn't bring up an error box, but you can MessageBox if you want manually.
Feb 3 '06 #5
In article <_Z**************@fe03.lga>,
"Jim Langston" <ta*******@rocketmail.com> wrote:
"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news.east.ea rthlink.net...
In article <11*********************@g47g2000cwa.googlegroups. com>,
"noopathan" <ms*****@gmail.com> wrote:
I have two strings as below

string A = "102030405060.wldep.1251.jpg";
string B= "102030405060.wldep.1251.pdf";

I want the word after last dot in other two strings
i.e;
string C = "jpg";
string D="pdf";

Early code help is greatly appreciated.

regards

Jango


assert( A.rfind('.') != string::npos );
string C = A.substr( A.rfind('.') + 1 );


Don't use assert for something like this you want to put into production.
Once you turn off debug mode asserts disappear. So it would totally ignore
that. I would rather do:

std::string C;
if ( A.rfind('.') != string::npos )
C = A.substr( A.rfind('.') + 1 );

That'll work in production or debug. Yes, it assigns a null string and
doesn't bring up an error box, but you can MessageBox if you want manually.


It all depends on what you want to accomplish. Your solution is good if
the program should expect to occasionally get a string without a '.' in
it (for example if the user is entering the string.)

--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 3 '06 #6

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

Similar topics

4
2263
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
32
14760
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
15
16278
by: Daren | last post by:
Hi, I need to be able to split large string variables into an array of lines, each line can be no longer than 70 chars. The string variables are text, so I would additionally like the lines...
4
3468
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
10
8484
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
6
9245
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
6
380
by: marco.minerva | last post by:
Hi all! I have a file in which there are some expressions such as "kindest regard" and "yours sincerely". I must create a phyton script that checks if a text contains one or more of these...
29
23116
by: aarthi28 | last post by:
Hi, I have written this code, and at the end, I am trying to write a vector of strings into a text file. However, my program is nor compiling, and it gives me the following error when I try to...
8
2604
by: Nehil | last post by:
how can u find whether a no has consecutive zero bits either in from LSB or MSB. if they exist in between, then what to do? plz clarify.
0
7124
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
6998
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
7200
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...
1
6884
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
7375
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
5460
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,...
1
4904
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...
0
4586
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...
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.