Re: a string, a string array and character array
- From: Walter Roberson <roberson@xxxxxxxxxxxx>
- Date: Wed, 10 Dec 2008 11:49:44 -0600
Rune Allnor wrote:
A "char array" is an array that contains numerical data of
type "char", that is numbers in the range -128 - 127.
I would have to dig for a while to find a computer language
which defined its "char" to be in the range -128 to 127.
For example, C doesn't: "char" has an implementation-defined
range that can be signed or unsigned; "char" in C has a certain
minimum span of values, but there is no maximum span of values
defined in C, and there -are- C implementations in which 'char'
is a 32 bit quantity (e.g., Cray, and some DSPs.)
Possibly one of the BASIC defined in terms of -128 to 127.
Defining char as unsigned is more common in computer languages.
In Matlab, as of somewhere around version 7.0 (I'd have to research
the exact version), individual char are stored as unsigned values from 0 to 65535.
char(65535) + 0
ans =
65535
Warning: Out of range or non-integer values truncated during conversion to character.char(65536) + 0
ans =
65535
A "string" is an array that contains characters (letters)
instead of numbers. Certain operations work differently
with strings, like sorting. With strings, lowercase and
uppercase letters have different numerical values but the
same ordinal value (that is, "Abc" and "abc" are equivalent).
Urrr, I've never encountered that definition of "string" before.
In Matlab, a "string" is a common phrasing for a row vector of char.
A character array is an array of character type; if the array happens
to be two dimensional and the first dimension happens to be 1, then
the character array could also be called a "string". Two dimensional
arrays of characters are common in Matlab; the older convention in Matlab is
that if you need to pass in a list of strings, that you put them all
together in a two-dimensional array of characters whose width is the
width of the longest of the individual strings and with all of the shorter
lines right-padded with blanks.
Matlab also refers to "cell strings"; see the documentation
for cell2str().
--
..signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?
.
- Follow-Ups:
- Re: a string, a string array and character array
- From: Rune Allnor
- Re: a string, a string array and character array
- References:
- a string, a string array and character array
- From: Arthur Zheng
- Re: a string, a string array and character array
- From: Rune Allnor
- a string, a string array and character array
- Prev by Date: Imagesc to visualize matrices
- Next by Date: Re: a string, a string array and character array
- Previous by thread: Re: a string, a string array and character array
- Next by thread: Re: a string, a string array and character array
- Index(es):
Relevant Pages
|