⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wzdstr.cpp

📁 《vc++扩展编程实例》源码。运用Visual C++ 5.0或6.0的高级编程技巧
💻 CPP
字号:
// WzdStr.cpp
//

#include "stdafx.h"
#include "WzdStr.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWzdString

// extracts characters from beg to end
CString CWzdString::Extract(int beg,int end)
{
	return Mid(beg-1,end-beg+1);
}

// stores binary as HEX ascii string
void CWzdString::PutBinary(LPBYTE pByte,int len)
{
	Empty();
	CString hex;
	for (int i=0;i<len;i++)
	{
		hex.Format("%02X",pByte[i]);
		*this+=hex;
	}
}

// retrieves HEX ascii string as binary
// returned value is actual binary length
int CWzdString::GetBinary(LPBYTE pByte,int maxlen)
{
	// make sure the string contains only valid hex characters
	if (SpanIncluding("0123456789aAbBcCdDeEfF") != *this)
	{
		return 0;
	}
	
	// make sure less then max bytes
	int len=GetLength();
	if (len>maxlen*2)
	{
		len=maxlen*2;
	}

	// pad HEX to even number
	CString hex=*this;
	if ((len % 2) != 0)
	{
		len++;
		hex+="0";
	}

	// convert to binary
	len/=2;
	for (int i = 0; i <len; i++)
	{
		int b;
		sscanf(hex.Mid((i * 2), 2), "%02X", &b);
		pByte[i] = (BYTE)b;
	}
	return(len);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -