Solved

Getting a substring position in a CString Var.?

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

860 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