Solved

Getting a substring position in a CString Var.?

Posted on 1998-02-25
3
665 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 93
Separate into files by filename 12 82
fizzArray2 challenge 1 79
Way to decrease size of apk file 9 67
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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