Solved

Getting a substring position in a CString Var.?

Posted on 1998-02-25
3
644 Views
Last Modified: 2013-11-20
How do I get the start position of a sub string within
a CString object???
I have tried to use ->
CString mText("abcdefghi");
int mInitPos = mText.Find("gh");
// All that this returns is a '1' not the start position in
the string..Is their something I am doing wrong..
please give an example..
0
Comment
Question by:simlox
3 Comments
 

Accepted Solution

by:
svel earned 30 total points
Comment Utility
Hi,
What you have done is correct. It is supposed to return the correct index of the substring. but I don't know why its returning 1.
I have written the sample code to check( same as above ), It returns 6. Which means, your string(mText) is getting changed somewhere or your substring is wrong.
My Suggestions :
Please check the value of mText and substring.


0
 
LVL 1

Expert Comment

by:atari
Comment Utility
If this didn't work, then try also

CString mText(_T("abcdefghi"));

and then call the above code

int position=mText.Find(_T("gh"));

Maybe this will work.
0
 

Expert Comment

by:lato
Comment Utility
You can always use the strstr() C function.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now