Solved

Getting a substring position in a CString Var.?

Posted on 1998-02-25
3
689 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 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