Adding binary values to strings

Use this

	myString = Convert::ToChar(MyVariable0);
	myString += Convert::ToChar(MyVariable1);
	myString += Convert::ToChar(MyVariable2);

(more…)

Arrays of Strings

Creating String Arrays

Different ways to create string arrays:


	array ^myArray = gcnew array(10);
	//or
	array ^myArray;
	myArray = gcnew array(10);
	//or
	array ^myArray =  {"channel8", "channel9", "technet" , "channel10", "msdn"};

(more…)

Convert Bytes To A String


	array<Byte> ^RxData = gcnew array<Byte>(2);
	RxData[0] = 'A';
	RxData[0] = 'B';
	String ^sTemp;

 (more...)

Convert String To Byte Array

String Direct To Byte Array


	String ^sTemp;
	array<Byte> ^TxData;

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

 (more...)

Convert String To Unicode Values

String Conversion To Unicode Byte Array


using namespace System::Text;

	Encoding ^Unicode1 = Encoding::Unicode;
	array<Byte> ^UnicodeBytes = Unicode1->GetBytes("1234");		//Produces: 0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00

(more…)

Display Values In A String

Display Decimal Value


	MyString = String::Format("{0:D}", MyVariable);
	MyString = String::Format("{0:D6}", MyVariable);	//D6 formats value to 6 digits, inserting leading zero's if necessary

(more…)

String Builder

When you want to manipulate and edit strings use StringBuilder rather than String.


	StringBuilder^ myString = gcnew StringBuilder("Hello World", 30);
						//Start off with 30 character capacity (will auto grow as needed)

Strings General

The string type is a library type and is actaully an array of char or wchar_t. The last character in a string is always null.
The library takes care of managing the memory associated with storing the elements. As well as being less powerful, C-style strings are the root cause of many many security problems, so always use the string library instead.

(more…)

URI Encode String


	ConvertedString = System::Web::HttpUtility::UrlEncode(SomeString);

Value Internationalization Issues

Comma Instead Of Decimal Point

In countries such as Germany they use commas as decimal points (e.g. -0,136222).  So if your program is converting a string like this: (more…)

Working With Characters In Strings

Replace A Character In A String


	sTemp = "ABCDEF";
	sTemp = sTemp->Substring(1, 1);							//Get a single character from the source string
	Result = Result->Remove(LICENSER_PRODUCT_ID_1_INDEX, 1);		//Remove the character to be replaced in the destination string
	Result = Result->Insert(LICENSER_PRODUCT_ID_1_INDEX, sTemp);		//Add the character

Working With Strings

String Special Characters


sTemp += "\r\n"		//Add a newline
String ^sTemp =  = "\x7";	// ‘\x’ means ‘0x’ and the 1 of 2 digits that follow are a hex value for the character requried

 (more...)