Is String Value Numeric

  int i = 0; bool ValueIsNumeric = int::TryParse(MyStringValue, i); For larger values: UInt64 i = 0; ValueIsNumeric = UInt64::TryParse(MyStringValue, i);    

Read More

Sanitising strings for use in SQL statements

If possible don't sanitize your strings. Use parameterized queries instead, as they handle all sanitization. For MS-SQL //Convert single quotes to two single quotes TagDescription = TagDescription->Replace("'", "''"); For MySQL //Convert single quotes to two single quotes TagDescription = TagDescription->Replace("'", "\'");

Read More

Convert String To Unicode Values

String Conversion To Unicode Byte Array using namespace System::Text; array<Byte> ^MyArray = Encoding::Unicode->GetBytes(MyString); using namespace System::Text; Encoding ^Unicode1 = Encoding::Unicode; array<Byte> ^UnicodeBytes = Unicode1->GetBytes("1234"); //Produces: 0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00 Convert Unicode Bytes To String using namespace System::Text; MyString = Encoding::Unicode->GetString(MyByteArray); Then To Convert To Unicode Words int Count; UInt16 UnicodeValue; for (Count = 0; Count < UnicodeBytes->Length; Count […]

Read More

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: String ^sTemp; Single Value; sTemp = “1.234”; Value = Convert::ToSingle(sTemp); What you will actually get is 1234 in Value – the decimal point is ignored. Correctly Handling […]

Read 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

Read More

URI Encode String

ConvertedString = System::Web::HttpUtility::HtmlEncode(SomeString); ConvertedString = System::Web::HttpUtility::UrlEncode(SomeString); If its not available select project proiperties > Framework & References > add a reference to System.Web HtmlEncode – HTML encoding makes sure that text is displayed correctly in the browser and not interpreted by the browser as HTML. UrlEncode – Encodes a URL string. These method overloads can be used to encode […]

Read More

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, […]

Read 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)

Read More

Display Values In A String

Display Values With Decimal Places When formatting numbers you can use “0” as mandatory place and “#” as optional place. Display Decimal Value Display Decimal Places Display Hex Value Display Binary Value Display Software Version Typical Solution Display DateTime Link to all format codes Good Examples http://blogs.msdn.com/b/kathykam/archive/2006/03/29/564426.aspx Another Example

Read More

Adding binary values to strings

Use this myString = Convert::ToChar(MyVariable0); myString += Convert::ToChar(MyVariable1); myString += Convert::ToChar(MyVariable2); If you get a problem with starting a string do this myString = Convert::ToString(Convert::ToChar(MyVariable0)); myString += Convert::ToChar(MyVariable1); myString += Convert::ToChar(MyVariaqble2);

Read More