answersLogoWhite

0

A string is an array. To be precise, a string is an array where every element is a character type. The term string simply relates to the fact the array (like any other type of array) resides in contiguous memory, thus forming a string of characters in memory.

There are in fact two types of string array. The most common is the ASCII string, where each element is 1 byte in length (an array of type char). The other is the UNICODE string where each element is 2 bytes in length (an array of type wchar_t).

In essence, ASCII strings are constructed from character codes 0-255 in the standard ASCII character set, while UNICODE can represent up to 65,536 different character codes, the first 256 being the same as the ASCII character set. UNICODE is generally used to provide character codes that are not available in ASCII, however many systems (Microsoft in particular) handle all strings as UNICODE strings (converting to and from ASCII as required). If you do a lot of string manipulation, then it is often best to use UNICODE at all times to reduce the amount of conversions going on in the background (check your compiler's documentation for specifics).

When dealing with strings we often talk about string buffers. A buffer is simply an array of a specific size (allocated dynamically or statically) within which we can store a sequence of character codes. Since characters are consistently either one byte or two bytes long, it's easy to determine how many characters we can place in these buffers.

However, just to confuse matters, there is actually a third type of string known as a variable-width encoded string. Microsoft calls these MBCS strings, but this really means multibyte character set, which is not the same. The width of a character is determined by the encoding, not the character set. The details don't really concern us, but suffice to say, each character has variable-width and there are many different encoding schemes available. As a general rule, if you must deal with variable-width encoded strings, use UNICODE instead, and only encode as variable width when you must. It'll make your life a lot simpler in the long run.

You will undoubtedly encounter other types of string, such as std::string (and its UNICODE equivalent, std::wstring). This is really just an object that encapsulates a character array so you can use it just as you would a standard character array. However, do not let this fool you -- it is not a character array per se, it is merely a wrapper that mimics an array. There is an underlying array within the object's members, and several useful methods to manipulate the array (such as concatenating two strings), however memory management is handled by the object. While this simplifies things for programmers, it is not the most efficient way to store a string when that is all you want to do. But if you want to actually manipulate the string, then std:string is as good a way as any.

To make use std:string you must include in your project. Do not confuse this with which merely declares a set of functions for manipulating c strings and arrays (the old fashioned way). This header is often called "cstring", which is often confused with the Microsoft-specific class CString (note the captialisation). CString can be likened to std:string in a lot of respects and crops up virtually everywhere in Microsoft objects. It is actually derived from the CStringT template which is itself derived from CSimpleStringT. It is therefore more complex, but the interface is extremely simple to use and if you do a lot of string manipulation, then CString can make life that much easier. But as it is not part of the standard language, its best avoided when code must be shared between platforms.

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What is the array of string in c?

A string in C is stored in a 1 dimension array so an array of strings is simply a two dimension array.


How many constructors are there for the string class?

The String class has multiple Constructors. Some of them are: 1. String - new String(String val) 2. Character Array - new String(char[] array) 3. Character Array with index positions - new String(char[] array. int start, int end)


How do you convert a string into a character array?

A string is, by definition, a character array. No conversion is required.


What elements are in string?

A string is an array of characters.


What is the difference between array and string of array?

When we declare an array of characters it has to be terminated by the NULL , but termination by NULL in case of string is automatic.


How do you count the vowels in a string using PHP?

build an array of vowels then do a foreach on the array and then explode the string on the array value and the answer is -1 of the result


Is string an object?

No. A string is, by definition, a character array.


Is string is an object?

No. A string is, by definition, a character array.


Can you store non primitive data type in the array list?

Yes you can store non primitive data type variables in an array. String is a non primitive data type. You can declare a string array as: String a[]=new String[10];


Which function is used to retrive the part of the string?

If a string features a separator (e.g. a dot or a comma), use PHP's explode() function to get an array with the two parts: $string = "hello,joe" $array = explode(",", $string); $array[0] will be "hello" $array[1] will be "joe" If not, you may use substr() to return a certain length of a string


What does it mean to have a string split in java?

To have a string split in Java means that a string array, containing substrings (can be delimited by elements of a specified string or Unicode character array), is returned.


What do string and vector and array all inherit from that has the size method so you can take it as an argument?

string, vector and array do not have a common base class. Overload your function to accept either a string, a vector or an array.