{"id":187,"date":"2010-04-28T17:57:25","date_gmt":"2010-04-28T17:57:25","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=187"},"modified":"2022-02-17T06:24:05","modified_gmt":"2022-02-17T06:24:05","slug":"convert-string-to-byte-array","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/strings\/convert-string-to-byte-array","title":{"rendered":"Convert String To Byte Array"},"content":{"rendered":"<h4>String Direct To Byte Array<\/h4>\n<pre><code>\r\n\tString ^sTemp;\r\n\tarray&lt;Byte&gt; ^TxData;\r\n\r\n\tsTemp = \"Hello\";\r\n\tTxData = System::Text::Encoding::UTF8-&gt;GetBytes(sTemp);\r\n\r\n<\/code><\/pre>\n<h4>Lengthy Method<\/h4>\n<pre><code>\r\n\tString ^Filename;\r\n\tFilename = \"HELLO.TXT\";\r\n\r\n\tarray&lt;Char&gt; ^NameArray = Filename-&gt;ToCharArray();\r\n\tArray::Resize(NameArray, 13);\t\t\t\t\t\t\/\/If you need to ensure a minimum size use this\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[0]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[1]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[2]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[3]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[4]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[5]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[6]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[7]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[8]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[9]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[10]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[11]);\r\n\tTxData[ByteId++] = Convert::ToByte(NameArray[12]);\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>String Direct To Byte Array String ^sTemp; array&lt;Byte&gt; ^TxData; sTemp = &#8220;Hello&#8221;; TxData = System::Text::Encoding::UTF8-&gt;GetBytes(sTemp); Lengthy Method String ^Filename; Filename = &#8220;HELLO.TXT&#8221;; array&lt;Char&gt; ^NameArray = Filename-&gt;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++] = [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-strings"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":7,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":1131,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/187\/revisions\/1131"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}