converting CString to Char[100]
-
I want to Convert CString value to Char[100]; Please guide me. Thanks, Krishna
-
I want to Convert CString value to Char[100]; Please guide me. Thanks, Krishna
Not sure why
char[100]
... ??? ...why not get the size first then allocate the array dynamically? But, you can use theCString::GetBufferSetLength()
(allows you to specify maximum size) method then just copy the contents of the buffer to thechar[]
usingmemcpy()
. -
Not sure why
char[100]
... ??? ...why not get the size first then allocate the array dynamically? But, you can use theCString::GetBufferSetLength()
(allows you to specify maximum size) method then just copy the contents of the buffer to thechar[]
usingmemcpy()
.For Example i took char[100] As you mentioned i need to take the length of the string. Thankyou Albert.
-
I want to Convert CString value to Char[100]; Please guide me. Thanks, Krishna
LPSTR WideChar2MBCS( const CString& strCS )
{
const UINT wLen = strCS.GetLength() + 1;
UINT aLen = WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL);
LPSTR lpa = new char[aLen];
WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);
return lpa;
}maybe this will help you. myblog is: http://www.cppblog.com/stonexin/archive/2011/12/01/161280.html
-
LPSTR WideChar2MBCS( const CString& strCS )
{
const UINT wLen = strCS.GetLength() + 1;
UINT aLen = WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL);
LPSTR lpa = new char[aLen];
WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);
return lpa;
}maybe this will help you. myblog is: http://www.cppblog.com/stonexin/archive/2011/12/01/161280.html
-
For Example i took char[100] As you mentioned i need to take the length of the string. Thankyou Albert.
-
Use
strcpy()
or its wide character equivalent for the copy. For further information see here[^].Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
Forgot you can use that on a CString... :thumbsup:
-
Forgot you can use that on a CString... :thumbsup:
If I had $1 for everything I've forgotten ... ;)
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
LPSTR WideChar2MBCS( const CString& strCS )
{
const UINT wLen = strCS.GetLength() + 1;
UINT aLen = WideCharToMultiByte(CP_ACP,0,strCS,wLen,NULL,0,NULL,NULL);
LPSTR lpa = new char[aLen];
WideCharToMultiByte(CP_ACP,0,strCS,wLen,lpa,aLen,NULL,NULL);
return lpa;
}maybe this will help you. myblog is: http://www.cppblog.com/stonexin/archive/2011/12/01/161280.html
thanks its works.
chichewa translation services | urdu translation services | bengali translation services
-
I want to Convert CString value to Char[100]; Please guide me. Thanks, Krishna
CString str = _T( "Test string." );
char pBuffer[ 100 ];if( sizeof( TCHAR ) == 2 )
WideCharToMultiByte( CP_ACP, 0, ( WCHAR* )str.GetBuffer(), -1, pBuffer, 100, NULL, NULL );
else
{
char* pTemp = ( char* )str.GetBuffer();
memcpy_s( pBuffer, 100, pTemp, strlen( pTemp ) + 1 );
}