String Constructor (SByte*)
Initializes a new instance of the String class to the value indicated by a pointer to an array of 8-bit signed integers.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System::SByte*
A pointer to a null-terminated array of 8-bit signed integers.
| Exception | Condition |
|---|---|
| ArgumentNullException | value is nullptr. |
| ArgumentException | A new instance of String could not be initialized using value, assuming value is encoded in ANSI. |
| ArgumentOutOfRangeException | The length of the new string to initialize, which is determined by the null termination character of value, is too large to allocate. |
| AccessViolationException | value specifies an invalid address. |
The value parameter is assumed to point to an array representing a string encoded using the default ANSI code page (that is, the encoding method specified by Encoding::Default).
Note |
|---|
Because the default ANSI code page is system-dependent, the string created by this constructor from identical signed byte arrays may differ on different systems. Instead of using a signed byte array to instantiate a string, the recommended alternative is to use any of the overloads that take either an array of Char (the String::String(array<Char>) and String::String(array<Char>, Int32, Int32) constructors) or a pointer to an array of Char (the String::String(Char*) and String::String(Char*, Int32, Int32) constructors) as parameters. |
This constructor processes characters from value starting from the location specified by the pointer until a null character (hexadecimal 0x0000) is reached.
If the specified array is not null-terminated, the behavior of this constructor is system dependent. For example, such a situation might cause an access violation.
In C#, this constructor is defined only in the context of unsafe code.
The following simple example demonstrates how you can create an instance of the String class with this constructor.
// Null terminated ASCII characters in a simple char array char charArray3[4] = {0x41,0x42,0x43,0x00}; char * pstr3 = &charArray3[ 0 ]; String^ szAsciiUpper = gcnew String( pstr3 ); char charArray4[4] = {0x61,0x62,0x63,0x00}; char * pstr4 = &charArray4[ 0 ]; String^ szAsciiLower = gcnew String( pstr4,0,sizeof(charArray4) ); // Prints "ABC abc" Console::WriteLine( String::Concat( szAsciiUpper, " ", szAsciiLower ) ); // Compare Strings - the result is true Console::WriteLine( String::Concat( "The Strings are equal when capitalized ? ", (0 == String::Compare( szAsciiUpper->ToUpper(), szAsciiLower->ToUpper() ) ? (String^)"TRUE" : "FALSE") ) ); // This is the effective equivalent of another Compare method, which ignores case Console::WriteLine( String::Concat( "The Strings are equal when capitalized ? ", (0 == String::Compare( szAsciiUpper, szAsciiLower, true ) ? (String^)"TRUE" : "FALSE") ) );
- SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note