Solved

Getting a substring position in a CString Var.?

Posted on 1998-02-25
3
656 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
ID: 1316557
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
ID: 1316558
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
ID: 1316559
You can always use the strstr() C function.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 163
sum28 challenge 31 106
ShiftLeft challenge 21 76
Annoying "thing" blocks my view 4 82
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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