SysUtilsStrLCat (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example uses an edit control and a button on a form in an application. When the button is clicked, the edit control's text is split in halves that are copied into separate buffers. Then the contents of the buffers are displayed in a message box.

Code

void __fastcall TForm1::Button1Click(TObject *Sender) {
	String str, rightStr;
	str = Edit1->Text;
	wchar_t* FirstHalf = new wchar_t[StrLen(str.c_str()) / 2 + 2];
	wchar_t* SecHalf = new wchar_t[StrLen(str.c_str()) / 2 + 2];
	*FirstHalf = 0;
	*SecHalf = 0;
	int len = StrLen(str.c_str());
	StrLCat(FirstHalf, str.c_str(), len / 2);
	rightStr = str.SubString(len / 2 + 1, len - (len / 2));
	StrLCat(SecHalf, rightStr.c_str(), StrLen(rightStr.c_str()));
	Application->MessageBox(WideString(FirstHalf).c_bstr(), L"FirstHalf",
		MB_OKCANCEL);
	Application->MessageBox(WideString(SecHalf).c_bstr(), L"SecHalf",
		MB_OKCANCEL);
}

Uses