Search This Blog

Showing posts with label Cstring. Show all posts
Showing posts with label Cstring. Show all posts

Sunday, November 29, 2009

String Cstring comparision



/*
string and CSting Find, mid, left funtion
Example and comparison.
*/



#include <string> //string
using namespace std; //string


string strSample,strLeft,strRight,str;
size_t pos=0;
strSample="This is my sample";

pos=strSample.find("my");
if(pos!=string::npos)
{
strLeft=strSample.substr(0,pos);
//This is

strRight=strSample.substr(pos);
//my sample

str=strSample.substr(pos+strlen("my"));
// sample
}


CString csSample,csLeft,csRight,csStr;
int nPos=-1;
csSample="This is my sample";
if( (nPos=csSample.Find("my"))>-1)
{
csLeft=csSample.Left(nPos);
//This is

csRight=csSample.Mid(nPos);
//my sample

csStr=csSample.Mid(nPos+_tcslen("my"));
// sample

}

Saturday, October 31, 2009

To view all values and size of CStringArray in watch window

In watch window, we cannot view all the elements in a CStringArray .
We can view only the first element of the CStringArray.


To View all elements Please change the following settings [For Visual Studio 2008]:
1. Open the file "c:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\autoexp.dat" in notepad

2. Search for the line "[AutoExpand]" add the following line.

[AutoExpand]
CStringArray=size = <m_nSize> //Add this line


3. Search for the line "[Visualizer]" add the following line.

[Visualizer] //Add the below lines after this line

CStringArray{
children
(
#array
(
expr : ($e.m_pData[$i]),
size : ($e.m_nSize)
)
)
}

4. Save this file and close All Visual studio application and open again and try.

Saturday, February 28, 2009

How to convert CString into LPTSTR ?

CString csStr = "Hello";
LPTSTR lpStr = csStr.GetBuffer( 0 );
csStr.ReleaseBuffer();

Saturday, February 7, 2009

Useful Cstring Functions



//For replacing nonprintable and non-ASCII unicode to space
CString RemoveNonPrintableCharWithSpacer(LPCSTR lpText)
{
CString csData;
for(;*lpText!='\0'; lpText++)
{
if(*lpText<0 || *lpText>255)
{
csData += " ";
}
else
{
csData += *lpText;
}
}

return csData;
}



//For counting no of small characters
unsigned int CountSmallCharacters(LPCTSTR lpText)
{
unsigned int nSCharCount =0;
for(;*lpText!='\0'; lpText++)
{
if(*lpText>='a' && *lpText <='z')
nSCharCount++;
}
return nSCharCount;
}



//For counting no of characters
unsigned int CountCharacters(LPCTSTR lpText)
{
unsigned int nCharCount =0;
for(;*lpText!='\0'; lpText++)
{
if( (*lpText>='a' && *lpText <='z') || (*lpText>='A' && *lpText <='Z') )
nCharCount++;
}
return nCharCount;
}