String Direct To Byte Array


	String ^sTemp;
	array<Byte> ^TxData;

	sTemp = "Hello";
	TxData = System::Text::Encoding::UTF8->GetBytes(sTemp);

Lengthy Method


	String ^Filename;
	Filename = "HELLO.TXT";

	array<Char> ^NameArray = Filename->ToCharArray();
	Array::Resize(NameArray, 13);						//If you need to ensure a minimum size use this
	TxData[ByteId++] = Convert::ToByte(NameArray[0]);
	TxData[ByteId++] = Convert::ToByte(NameArray[1]);
	TxData[ByteId++] = Convert::ToByte(NameArray[2]);
	TxData[ByteId++] = Convert::ToByte(NameArray[3]);
	TxData[ByteId++] = Convert::ToByte(NameArray[4]);
	TxData[ByteId++] = Convert::ToByte(NameArray[5]);
	TxData[ByteId++] = Convert::ToByte(NameArray[6]);
	TxData[ByteId++] = Convert::ToByte(NameArray[7]);
	TxData[ByteId++] = Convert::ToByte(NameArray[8]);
	TxData[ByteId++] = Convert::ToByte(NameArray[9]);
	TxData[ByteId++] = Convert::ToByte(NameArray[10]);
	TxData[ByteId++] = Convert::ToByte(NameArray[11]);
	TxData[ByteId++] = Convert::ToByte(NameArray[12]);
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.