C++ Builder 參考手冊(cè) ? System::Sysutils ? StrToUIntDef
字符串轉(zhuǎn)無符號(hào)整數(shù)值
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:
unsigned __fastcall StrToUIntDef(const System::UnicodeString S, unsigned Default);
參數(shù):
- S:字符串;
- Default: 默認(rèn)值宪迟;
返回值:
- 無符號(hào)整數(shù)類型數(shù)值酣衷,如果轉(zhuǎn)換失敗,函數(shù)返回參數(shù) Default 的值踩验;
- 字符串可以是十進(jìn)制或十六進(jìn)制數(shù)據(jù):以 "0x" 開頭認(rèn)為是十六進(jìn)制數(shù)據(jù)鸥诽,否則認(rèn)為是十進(jìn)制商玫,不支持八進(jìn)制及其他進(jìn)制箕憾;
- 函數(shù) StrToUInt牡借、StrToUIntDef 和 TryStrToUInt 的區(qū)別:
? StrToUInt 轉(zhuǎn)換失敗拋出異常;
? StrToUIntDef 轉(zhuǎn)換失敗返回默認(rèn)值袭异;
? TryStrToUInt 轉(zhuǎn)換結(jié)果通過參數(shù)返回钠龙,函數(shù)返回值返回是否轉(zhuǎn)換成功。
例:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Add(StrToUIntDef(L"123",0));
Memo1->Lines->Add(StrToUIntDef(L"0123",0));
Memo1->Lines->Add(StrToUIntDef(L"123H",0));
Memo1->Lines->Add(StrToUIntDef(L"0x123",0));
Memo1->Lines->Add(StrToUIntDef(L"0xABCDE",0));
Memo1->Lines->Add(StrToUIntDef(L"0xFFFFFFFF",0));
}
運(yùn)行結(jié)果:第三個(gè)由于含有字母 'H' 轉(zhuǎn)換失敗御铃,返回默認(rèn)值 0 (函數(shù)的第二個(gè)參數(shù)值)碴里,其他的都轉(zhuǎn)換成功
相關(guān):
- System::Sysutils::IntToStr
- System::Sysutils::IntToHex
- System::Sysutils::UIntToStr
- System::Sysutils::Format
- System::Sysutils::FormatBuf
- System::Sysutils::StrToBool
- System::Sysutils::StrToBoolDef
- System::Sysutils::StrToCurr
- System::Sysutils::StrToCurrDef
- System::Sysutils::StrToDate
- System::Sysutils::StrToDateDef
- System::Sysutils::StrToDateTime
- System::Sysutils::StrToDateTimeDef
- System::Sysutils::StrToFloat
- System::Sysutils::StrToFloatDef
- System::Sysutils::StrToInt
- System::Sysutils::StrToIntDef
- System::Sysutils::StrToInt64
- System::Sysutils::StrToInt64Def
- System::Sysutils::StrToTime
- System::Sysutils::StrToTimeDef
- System::Sysutils::StrToUInt
- System::Sysutils::StrToUIntDef
- System::Sysutils::StrToUInt64
- System::Sysutils::StrToUInt64Def
- System::Sysutils::TimeToStr
- System::Sysutils::TryStrToBool
- System::Sysutils::TryStrToCurr
- System::Sysutils::TryStrToDate
- System::Sysutils::TryStrToDateTime
- System::Sysutils::TryStrToFloat
- System::Sysutils::TryStrToInt
- System::Sysutils::TryStrToInt64
- System::Sysutils::TryStrToTime
- System::Sysutils::TryStrToUInt
- System::Sysutils::TryStrToUInt64
- System::Sysutils
- std::atof, std::_ttof, std::_wtof
- std::_atold, std::_ttold, std::_wtold
- std::atoi, std::_ttoi, std::_wtoi
- std::atol, std::_ttol, std::_wtol
- std::atoll, std::_ttoll, std::_wtoll
- std::_atoi64, std::_ttoi64, std::_wtoi64
- std::strtof, std::_tcstof, std::wcstof
- std::strtod, std::_tcstod, std::wcstod
- std::strtold, std::wcstold, std::_strtold, std::_tcstold, std::_wcstold
- std::strtol, std::_tcstol, std::wcstol
- std::strtoll, std::_tcstoll, std::wcstoll
- std::strtoul, std::_tcstoul, std::wcstoul
- std::strtoull, std::_tcstoull, std::wcstoull
- <cstdlib>
C++ Builder 參考手冊(cè) ? System::Sysutils ? StrToUIntDef