Convert an array of DateTime values to a string and back again //CONVERT ARRAY OF DATE TIME TO COMMA SEPARATED STRING array<DateTime> ^MyDateTimeArray; String ^MyString; MyString = ""; for (Count = 0; Count < MyDateTimeArray->Length; Count++) MyString += MyDateTimeArray[Count].ToString("yyyy-MM-ddTHH:mm:ss.fffffff") + ","; //CONVERT COMMA SEPARATED STRING BACK TO ARRAY OF DATE TIME String ^sTemp; while (1) { […]
Category: Arrays
Delete Array Item
This is easier with a list as there's a built in function, but if you need to do it to an array: int IndexToRemove = 2; array<MyClassOrVariableName^> ^MyClassOrVariableName1_temp = gcnew array<MyClassOrVariableName^>(MyClassOrVariableName1->Length – 1); for (Count = 0; Count < MyClassOrVariableName1->Length; Count++) { if (Count < IndexToRemove) MyClassOrVariableName1_temp[Count] = MyClassOrVariableName1[Count]; else if (Count > IndexToRemove) MyClassOrVariableName1_temp[(Count […]
Sort Array
Sort Arrays Array::Sort Will sort an array in numerical order, and you can specify multiple arrays and they will bothbe sorted the same (i.e. an array of peoples names sorted according to another array of their ages), eg: Array::Sort(MyArrayWithSortKeys, MyOtherArray); //Sorts the entire Array using the default comparer. Sort An Array Of Custom Classes You […]
Array Functions
Array Class Type Array:: to get all the members of the Array class you can use Clear array Array::Clear(arrayName, 0, araryName->Length); //(name, start index, number of indexes to erase) Copy Array Array::Copy(Source, Dest, Length); //This will work with multi dimension arrays also Increase Array Size Array::Resize(myArr, myArr->Length + 5); //Resize the array to a bigger […]
.Arrays (Vectors)
Modern C++/CLI programs should almost always use vectors and iteriators in preference to the lower-level arrays and pointers, and strings to replace C-style array based character strings. Well designed programs use arrays and pointers only in the internals of class implementations where speed is essential. As well as being less powerful, C-style strings are the […]
Const Static Arrays
You can create constant arrays no problem and can do it at class level like this in the class variable area: static array<String^> ^MyStringrray = {"Name 1", "Name 2"}; static array<int> ^MyIntArray = {111, 222}; static array<UInt16> ^wCRCTable = { 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, […]
Create Byte Array From String
String ^data = “aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”; array<Byte> ^buffer = System::Text::Encoding::ASCII->GetBytes(data);