Click here to Skip to main content
15,892,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Type Cast Problem Pin
Stephen Hewitt24-Jul-06 13:53
Stephen Hewitt24-Jul-06 13:53 
Questionstring trim Pin
tanarnelinistit24-Jul-06 1:44
tanarnelinistit24-Jul-06 1:44 
AnswerRe: string trim Pin
_AnsHUMAN_ 24-Jul-06 2:00
_AnsHUMAN_ 24-Jul-06 2:00 
AnswerRe: string trim Pin
James R. Twine24-Jul-06 3:03
James R. Twine24-Jul-06 3:03 
GeneralRe: string trim Pin
Blake Miller24-Jul-06 12:13
Blake Miller24-Jul-06 12:13 
GeneralRe: string trim Pin
James R. Twine24-Jul-06 14:09
James R. Twine24-Jul-06 14:09 
AnswerRe: string trim Pin
David Crow24-Jul-06 4:14
David Crow24-Jul-06 4:14 
AnswerRe: string trim Pin
Zac Howland24-Jul-06 6:29
Zac Howland24-Jul-06 6:29 
Method using CString:

char buffer[17] = {0};
InitializeBuffer(buffer);	// put some value into it
CString strBuffer(buffer);
strBuffer.TrimLeft();
strBuffer.TrimRight();
memset(buffer, 0, 17);
strncpy(buffer, strBuffer, 16);


Method using std::string:

char buffer[17] = {0};
InitializeBuffer(buffer);	// put some value into it
std::string sBuffer(buffer);
int start_pos = sBuffer.find_first_not_of("\t\n\r ");
int end_pos = sBuffer.find_last_not_of("\t\n\r ");
if (start_pos == npos)
{
	start_pos = 0;
}
if (end_pos = npos)
{
	end_pos = strlen(buffer) - 1;
}
std::string sTemp = sBuffer.substr(start_pos, end_pos - start_pos + 1);
memset(buffer, 0, 17);
strncpy(buffer, sTemp.c_str(), 16);


Method using char:

int FindFirstNotOf(const char* chars, size_t chars_size, const char* str, size_t str_size)
{
	int ret = -1;
	for (int i = 0; i < str_size; ++i)
	{
		bool bFound = false;
		for (int j = 0; j < chars_size; ++j)
		{
			if (str[i] == chars[j])
			{
				bFound = true;
				break;
			}
		}

		if (bFound == false)
		{
			ret = i;
			break;
		}
	}
	
	return ret;
}

int FindLastNotOf(const char* chars, size_t chars_size, const char* str, size_t str_size)
{
	int ret = -1;
	for (int i = str_size - 1; i >= 0; --i)
	{
		bool bFound = false;
		for (int j = 0; j < chars_size; ++j)
		{
			if (str[i] == chars[j])
			{
				bFound = true;
				break;
			}
		}

		if (bFound == false)
		{
			ret = i;
			break;
		}
	}
	
	return ret;
}

char buffer[17] = {0};
InitializeBuffer(buffer);	// put some value in there
char chars[5] = "\t\r\n ";
int start_pos = FindFirstNotOf(chars, 5, buffer, 17);
int end_pos = FindLastNotOf(chars, 5, buffer, 17);

if (start_pos == -1)
{
	start_pos = 0;
}

if (end_pos == -1)
{
	end_pos = strlen(buffer) - 1;
}

char newBuffer[17] = {0};
strncpy(newBuffer, &buffer[start_pos], end_pos - start_pos);
memset(buffer, 0, 17);
strncpy(buffer, newBuffer, 16);


If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

AnswerRe: string trim Pin
James R. Twine24-Jul-06 8:10
James R. Twine24-Jul-06 8:10 
QuestionDatabase connection in vc++ Pin
ningthemcha24-Jul-06 1:04
ningthemcha24-Jul-06 1:04 
AnswerRe: Database connection in vc++ Pin
_AnsHUMAN_ 24-Jul-06 1:19
_AnsHUMAN_ 24-Jul-06 1:19 
AnswerRe: Database connection in vc++ Pin
David Crow24-Jul-06 2:59
David Crow24-Jul-06 2:59 
QuestionDisplaying the content of control to new form contron Pin
ningthemcha24-Jul-06 1:02
ningthemcha24-Jul-06 1:02 
AnswerRe: Displaying the content of control to new form contron Pin
_AnsHUMAN_ 24-Jul-06 2:33
_AnsHUMAN_ 24-Jul-06 2:33 
AnswerRe: Displaying the content of control to new form contron Pin
Hamid_RT24-Jul-06 2:41
Hamid_RT24-Jul-06 2:41 
QuestionRe: Displaying the content of control to new form contron Pin
David Crow24-Jul-06 3:03
David Crow24-Jul-06 3:03 
Questionasynchronized I/O == multiplexing I/O? Pin
George_George24-Jul-06 0:57
George_George24-Jul-06 0:57 
AnswerRe: asynchronized I/O == multiplexing I/O? Pin
peterchen24-Jul-06 2:12
peterchen24-Jul-06 2:12 
GeneralRe: asynchronized I/O == multiplexing I/O? [modified] Pin
George_George25-Jul-06 2:06
George_George25-Jul-06 2:06 
QuestionSet Focus to Button? Pin
bosfan24-Jul-06 0:37
bosfan24-Jul-06 0:37 
AnswerRe: Set Focus to Button? Pin
toxcct24-Jul-06 0:41
toxcct24-Jul-06 0:41 
GeneralRe: Set Focus to Button? Pin
bosfan24-Jul-06 1:09
bosfan24-Jul-06 1:09 
AnswerRe: Set Focus to Button? Pin
_AnsHUMAN_ 24-Jul-06 0:42
_AnsHUMAN_ 24-Jul-06 0:42 
GeneralRe: Set Focus to Button? Pin
bosfan24-Jul-06 1:26
bosfan24-Jul-06 1:26 
QuestionReading text from where mouse is double clicked!!! Pin
_AnsHUMAN_ 24-Jul-06 0:20
_AnsHUMAN_ 24-Jul-06 0:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.