C++ Builder 參考手冊 ? System::Sysutils ? BytesOf
把字符串按照系統(tǒng)默認(rèn)編碼轉(zhuǎn)成字節(jié)數(shù)組
頭文件:#include <System.SysUtils.hpp>
命名空間:System::Sysutils
函數(shù)原型:
System::DynamicArray<System::Byte> __fastcall BytesOf(const System::UnicodeString Val);
System::DynamicArray<System::Byte> __fastcall BytesOf(const System::WideChar Val);
System::DynamicArray<System::Byte> __fastcall BytesOf(const System::RawByteString Val);
System::DynamicArray<System::Byte> __fastcall BytesOf(const void * Val, const int Len);
System::DynamicArray<System::Byte> __fastcall BytesOf(const char Val);
參數(shù):
- Val:字符或字符串
- Len:字符串長度
返回值:
- 把 Val 按照系統(tǒng)默認(rèn)編碼轉(zhuǎn)成的字節(jié)數(shù)組嗦嗡;
? 參數(shù) Val 為 UnicodeString 類型時(shí)左医,把 Val 轉(zhuǎn)成系統(tǒng)默認(rèn)編碼 (ANSI 或 UTF-8) 的字符串诽偷,再把轉(zhuǎn)換之后的字符串逐個(gè)字節(jié)復(fù)制到返回值數(shù)組里面;
? 參數(shù) Val 為 WideChar 類型時(shí)皱坛;把只含有一個(gè) Val 的字符串轉(zhuǎn)成系統(tǒng)默認(rèn)編碼 (ANSI 或 UTF-8) 的字符串,再把轉(zhuǎn)換之后的字符串逐個(gè)字節(jié)復(fù)制到返回值數(shù)組里面豆巨;
? 參數(shù) Val 為 RawByteString 類型時(shí)剩辟,直接把 Val 里面的數(shù)組復(fù)制到返回值字節(jié)數(shù)組里面,不經(jīng)過編碼轉(zhuǎn)換;
? 參數(shù) Val 為 void * 類型時(shí)贩猎,從 Val 指向位置開始復(fù)制 Len 個(gè)字節(jié)到返回值字節(jié)數(shù)組里面熊户,不經(jīng)過編碼轉(zhuǎn)換;
? 參數(shù) Val 為 char 類型時(shí)吭服,返回的數(shù)組只有 1 個(gè)自己嚷堡,就是 Val 本身,不經(jīng)過編碼轉(zhuǎn)換艇棕; - 可以認(rèn)為是 AnsiString s = Val; 返回 s.c_str() 包含 s.Length() 個(gè)字節(jié)蝌戒;
- BytesOf 內(nèi)部通過調(diào)用 TEncoding::Unicode->Default(Value); 來實(shí)現(xiàn)的;
- 系統(tǒng)默認(rèn)的編碼沼琉,UTF-8 或 ANSI (請參考《C++ Builder 的字符串類型北苟、字符類型、字符編碼》)打瘪。
相關(guān):
- System::Sysutils::BytesOf
- System::Sysutils::WideBytesOf
- System::Sysutils::PlatformBytesOf
- System::Sysutils::StringOf
- System::Sysutils::WideStringOf
- System::Sysutils::PlatformStringOf
- System::Sysutils::ByteLength
- System::Sysutils::CharLength
- System::Sysutils::StrCharLength
- System::Sysutils::AnsiLastChar
- System::Sysutils::AnsiStrLastChar
- System::Sysutils::AnsiPos
- System::Sysutils::AnsiStrPos
- System::Sysutils::AnsiStrScan
- System::Sysutils::AnsiStrRScan
- System::Sysutils::CharToElementIndex
- System::Sysutils::CharToElementLen
- System::Sysutils::ElementToCharIndex
- System::Sysutils::ElementToCharLen
- System::Sysutils::TEncoding
- System::Sysutils
- std::mblen
- std::_mbstrlen
- <cstdlib>
- std::strlen, std::_fstrlen, std::_tcslen, std::wcslen
- <cstring>
C++ Builder 參考手冊 ? System::Sysutils ? BytesOf