|
I was looking through the help for " _lfind " function but having trouble using it. Could anyone help please?
This is my situation
I have three CString Variables:
m_strEnterData, m_strFindData, m_DisplayResult
m_strEnterData has the input string.
m_strFindData has the string I am searching in m_strEnterData.
m_DisplayResult is where I want to display the result
I saw the syntax for _lfind in the help but having trouble fitting it for my scenario. Can someone help ?
Thank you so much. This board has been a lifesaver.
M
|
|
|
|
|
i´m not a MFC guy so i might be wrong but try this...
int index = m_strEnterData.Find( m_strFindData ) ;
if( index != -1 ) // has it found it?
{
m_DisplayData = m_strEnterData.Mid( index, m_strFindData.Length() ) ;
}
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
Do you mean you want to search m_strEnterData for m_strFindData and then put the index of the location into m_DisplayResult? If so, why should m_DisplayResult be a CString? If not, what's supposed to be in m_DisplayResult ?
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
Yes you are right. Search for m_strFindData in m_strEnterData. If it is not found, move a message to m_strDisplayResult saying "not found".
|
|
|
|
|
Anyone managed to use custom draw on toolbars? I´m getting the notification messages but some options doesn´t seem to work, and the others are really poorly documented. I want to use "clrBtnHighlight", but the docs say that the item should have the tbstyle_marked to function properly, and searching for this style on the web i´ve only found "Version 4.71. The button is marked. The interpretation of a marked item is dependent upon the application".
Any help would be appreciated
Gabriel
Old C programmers never die. They just cast into void
|
|
|
|
|
I am trying to use string reverse (_strrev) function to reverse a string. Looks like string reverse does not like the data that it is reversing to be of the type CString.
Is there another function for this or should I convert it to a character type?
Thank you
M
|
|
|
|
|
CString str = "text";
char* szReversed;
szReversed = _strrev(str.GetBuffer(0));
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
|
Tom Archer wrote:
szReversed = _strrev(str.GetBuffer(0));
The OP may have to call ReleaseBuffer(...) after reversing the string if the CString itself continues to be used... Of course, at this point szReversed should be treated as a const pointer...
Peace!
-=- James.
(Try Check Favorites Sometime!)
|
|
|
|
|
Good point, James. I omitted mentioning the CString::ReleaseBuffer in this example because I assumed that the CString would not be used any further. I should probably include a sentence about using the CString::ReleaseBuffer when prescribing the CString::GetBuffer function.
Cheers,
Tom Archer
Author - Inside C#, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
You should ReleaseBuffer call after you´re ready with the szReversed!!!
While you´re poiting to the CString buffer it should be locked.;)
|
|
|
|
|
KarstenK wrote:
You should ReleaseBuffer call after you´re ready with the szReversed!!!
While you´re poiting to the CString buffer it should be locked.
While you are manipulating the buffer, the buffer should be locked. And, from the OP's original question: "I am trying to use string reverse (_strrev) function to reverse a string", so (s)he is done with manipulating szReversed after the contents have been reversed.
The problem is that if the OP tried to append to the CString right after the call to ::strrev(...) , the reversed CString would likely be lost. But not if CString::ReleaseBuffer(...) had been called.
" "
Peace!
-=- James.
"Fat people are hard to kidnap."
(Try Check Favorites Sometime!)
|
|
|
|
|
It seems to be so easy to use in this case "CString::MakeReverse()" that I tought there should be some tricky stuff.![Confused | :confused:](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|
How do you delete all items in a CListBox object?
|
|
|
|
|
I believe you are looking for MyListBox.ResetContent();
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|
|
Yes that's the one
Thanks!
|
|
|
|
|
I need some help with sort function in Visual C++.
Here is the situation :
I have a variable "m_strEditData" whose type is CString. I want to sort the string and move the data to another CString "m_strResultData".
I want this to be an inline code and not called as a function. Can anyone help me with this?
Greatly appreciated.
M
|
|
|
|
|
Do you mean sorting the characters your string is composed of? If so, this should do:
#include <algorithm>
...
m_strResultData=m_strEditData;
int nLength=m_strResultData.GetLength();
LPSTR buffer=m_strResultData.GetBuffer(nLength);
std::sort(buffer,buffer+nLength);
m_strResultData.ReleaseBuffer();
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you.
The Sort worked but as I was testing I rank into a situation (explained below). Is there a way to solve it.
Input data---> acbde
After sort function---> abcde
This is fine. But if I enter in input data
Input data----> This is my dog
Output ===> Sort all the characters together.
Is there a way to just sort only on the first character.
The result of my example after the sort would be :
"dog is my This".
Is this easily possible?
Thank you
M
|
|
|
|
|
This can be done, but involves a little more work. Here's an outline of the method:
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
...
std::vector<std::string> v;
std::istringstream istr((LPCSTR)m_strEnterData);
for(;;){
std::string s;
istr>>s;
if(s.empty())break;
v.push_back(s);
}
std::sort(v.begin(),v.end());
m_strDisplayResult="";
for(std::vector<std::string>::const_iterator it=v.begin();
it!=v.end();
++it){
if(it!=v.begin())m_strDisplayResult+=" ";
m_strDisplayResult+=it->c_str();
} (Sort of, I haven't compiled this.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thank you. I am going to review it and try to understand it.
I am not familiar with Vector operation but I am excited about learning it. I have a book. I will read more and will let you know.
Thank you
M
|
|
|
|
|
Thank you. I am going to review it and try to understand it.
I'm glad you decided to do so. STL can help you be more productive and write more robust code. Usually, trying to do this kind of things by hand results in off-by-one errors and mistakes like that.
In case you're interested, Christian Grauss has written several tutorials on different aspects of STL. Check them out at the STL section here at CodeProject. Good luck!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
Which function in CListBox returns the selected items textstring? ![Confused | :confused:](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|
CString buff;
GetText(GetCurSel(), buff);
GetSelCount(); will return the number of selected items in a listbox if it's a multi-selection enabled.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|