SysUtilsStrLComp (C++)
Description
This example requires two text edits and a button. Enter text in the two text edits and click the button to compare the strings.
Code
#include <algorithm> // For the min function
void __fastcall TForm1::Button1Click(TObject *Sender)
{
wchar_t* szResult = new wchar_t[Edit1->Text.Length() + Edit2->Text.Length() + 65];
int len = std::min(Edit1->Text.Length(), Edit2->Text.Length());
int iResult = Sysutils::StrLComp(
Edit1->Text.w_str(), Edit2->Text.w_str(), len + 1);
StrCopy(szResult, L"The first ");
StrCat(szResult, IntToStr(len).w_str());
StrCat(szResult, L" characters of ");
StrCat(szResult, Edit1->Text.w_str());
if (iResult < 0)
StrCat(szResult, L" are less than the first ");
else if (iResult > 0)
StrCat(szResult, L" are greater than the first ");
else
StrCat(szResult, L" are equal to the first ");
StrCat(szResult, IntToStr(len).w_str());
StrCat(szResult, L" characters of ");
StrCat(szResult, Edit2->Text.w_str());
ShowMessage(szResult);
delete [] szResult;
}
Uses
- System.SysUtils.StrLComp ( fr | de | ja )