Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
a string, a string array and character array

Subject: a string, a string array and character array

From: Arthur Zheng

Date: 10 Dec, 2008 16:50:19

Message: 1 of 24

Hi,
What is the difference between "a string", "a string array" and "character array" in Matlab? Can anyone show me the difference by an example? thanks!

Hao Zheng (Arthur)
ECE, Georgia Tech

Subject: a string, a string array and character array

From: Rune Allnor

Date: 10 Dec, 2008 17:13:23

Message: 2 of 24

On 10 Des, 17:50, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> Hi,
> What is the difference between "a string", "a string array" and "character array"

A "char array" is an array that contains numerical data of
type "char", that is numbers in the range -128 - 127.
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).

In certain programming languages opereations like "+" work
a bit differently, as with char arrays a+b will give the
numerical values stored in array a added to the numerical
values stored in array b, while for strings "abc"+"def"
results in the string "abcdef".

Rune

Subject: a string, a string array and character array

From: Arthur Zheng

Date: 10 Dec, 2008 17:36:01

Message: 3 of 24

Rune Allnor <allnor@tele.ntnu.no> wrote in message <8df61a1e-0a2a-4caf-aae9-e7b905e6b160@k24g2000pri.googlegroups.com>...
> On 10 Des, 17:50, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> > Hi,
> > What is the difference between "a string", "a string array" and "character array"
>
> A "char array" is an array that contains numerical data of
> type "char", that is numbers in the range -128 - 127.
> 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).
>
> In certain programming languages opereations like "+" work
> a bit differently, as with char arrays a+b will give the
> numerical values stored in array a added to the numerical
> values stored in array b, while for strings "abc"+"def"
> results in the string "abcdef".
>
> Rune

---------------------------------------------------------------------------------------------
I am still confused... First of all, what is the difference between "a string" and "a string array"?

Subject: a string, a string array and character array

From: Walter Roberson

Date: 10 Dec, 2008 17:49:44

Message: 4 of 24

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

>> char(65536) + 0
Warning: Out of range or non-integer values truncated during conversion to character.

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

Subject: a string, a string array and character array

From: Rune Allnor

Date: 10 Dec, 2008 18:05:49

Message: 5 of 24

On 10 Des, 18:49, Walter Roberson <rober...@hushmail.com> wrote:
> 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,

The OP is clearly a newbie. I think it is premature to
start splitting hairs at this level.


> > 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.

I suppose you can read? That you are familiar with the
lexical sorting of words? And that you have some at least
peripherical knowledge of the ASCII (or ANSI) character
sets?

As for programming languages, the above is how strings
work in C++.

Rune

Subject: a string, a string array and character array

From: Arthur Zheng

Date: 10 Dec, 2008 19:25:04

Message: 6 of 24

Let's talking within the range of matlab. What is the difference between "a string" and "a string array"?

Subject: a string, a string array and character array

From: NZTideMan

Date: 10 Dec, 2008 19:41:00

Message: 7 of 24

On Dec 11, 8:25=A0am, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> Let's talking within the range of matlab. What is the difference between =
"a string" and "a string array"?

Easiest to explain with an example. Try this:
str=3D'Hello World'; % a string
stra=3Dstr2mat('Hello','World'); % a string array

size(str) gives 1 11, in other words a row vector
size(stra) gives 2 5, in other words a matrix or "string array"
So a string array is simply some rows of strings (see Walter's post
for a definition).

Subject: a string, a string array and character array

From: Walter Roberson

Date: 10 Dec, 2008 20:12:15

Message: 8 of 24

Rune Allnor wrote:
> On 10 Des, 18:49, Walter Roberson <rober...@hushmail.com> wrote:
>> 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,
 
> The OP is clearly a newbie. I think it is premature to
> start splitting hairs at this level.

I disagree. You gave an authoritative-sounding answer that was
wrong for Matlab (which does not have negative character values)
and was wrong for the C++ language that you were importing the semantics of:

According to ISO/IEC 14882:1998(E) final draft:

http://www.kuzbass.ru:8086/docs/isocpp/basic.html#basic.fundamental
  -1- Objects declared as characters (char) shall be large enough to store
  any member of the implementation's basic character set. If a character from
  this set is stored in a character object, the integral value of that
  character object is equal to the value of the single character literal form
  of that character. It is implementation-defined whether a char object can
  hold negative values.
 
 
>>> 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.

> I suppose you can read? That you are familiar with the
> lexical sorting of words? And that you have some at least
> peripherical knowledge of the ASCII (or ANSI) character
> sets?

> As for programming languages, the above is how strings
> work in C++.

"Abc" and "abc" are, in C++, string literals [lex.string],
http://www.kuzbass.ru:8086/docs/isocpp/lex.html#lex.string
and string literals do NOT behave in the way you described.
Members of class string [lib.strings]
http://www.kuzbass.ru:8086/docs/isocpp/lib-strings.html
do not behave as you describe either: whether 'A' and 'a'
are treated the same depends upon the traits::eq() method
or the traits::compare() method (depending upon the exact
operation involved). Perhaps I am just not looking in the correct place,
but I see no evidence in [lib.strings] that -requires- "Abc" to be
treated as equivalent to "abc" for any purpose. I imagine it would
depend upon the Locale in effect -- and since you reference
ASCII and ANSI, you are implicitly referencing the "C" locale, in
which 'A' and 'a' would NOT compare as equal.

Note that [lib.strings] does not define any sort method and the text
of that section does not even use the word "sort". The compare() methods
of that section all refer back to traits.

Lexical sorting of strings is a messy topic, and the "right" way to do lexical
sorts is context-dependent, not something that can be encoded in a per-character
table. For example there is continued controversy in
library science over how to sort titles that start with the article "The",
and in practice it can come down to the role that the article is playing
in the title: e.g., "The Winning Strategy" could sort differently depending
on the emphasis that the author was placing on the fact that the winning
strategy being described was the *only* winning strategy. Compare the
theological implications of sorting as "Holy Bible, The"
against "The Holy Bible".

Subject: a string, a string array and character array

From: Walter Roberson

Date: 10 Dec, 2008 20:30:11

Message: 9 of 24

Arthur Zheng wrote:
> Let's talking within the range of matlab. What is the difference between "a string"
> and "a string array"?

"string array" is used, as best I can see, only in discussions of Mex routines,
where it is "an mxArray having the mxCHAR_CLASS class", which is the same thing
as a "character array", the term used in the rest of Matlab.

When "string" is used in Matlab, it refers to a row array of character, which
is to say an array of type character in which the first dimension is 1, the
second dimension is 1 or more, and all remaining dimensions are 1.

Otherwise, Matlab refers to character arrays, in which some additional dimension
might be something other than 1.

You might be confused by references to a "cell string array" or a "cell array
of strings". The "cell" is key there and "string array" cannot be removed from
the phrase without distorting the meaning severely. A cell string array
or a cell array of strings is a cell array, the entries of which are strings
(that is, row array of char.)

{'Hi', 'There'}

is a cell string array: that is, it is a cell array, the first cell of which
contains the 1 x 2 character array 'Hi', and the second cell of which contains
the 1 x 5 character array 'There'. A cell string array is an instance of a
generalized cell array; for example, {'Hi' 173 'There'} is a valid cell array,
the middle cell of which contains the 1 x 1 double array with the value 173,
and a cell string array is a cell array in which all the entries happen to be
strings.

--
.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)?

Subject: a string, a string array and character array

From: Arthur Zheng

Date: 10 Dec, 2008 20:53:02

Message: 10 of 24

NZTideMan <mulgor@gmail.com> wrote in message <41f10df9-2d98-4394-845b-f2815691f805@v39g2000pro.googlegroups.com>...
> On Dec 11, 8:25=A0am, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> > Let's talking within the range of matlab. What is the difference between =
> "a string" and "a string array"?
>
> Easiest to explain with an example. Try this:
> str=3D'Hello World'; % a string
> stra=3Dstr2mat('Hello','World'); % a string array
>
> size(str) gives 1 11, in other words a row vector
> size(stra) gives 2 5, in other words a matrix or "string array"
> So a string array is simply some rows of strings (see Walter's post
> for a definition).
----------------------------------------------------------------------
What is "3D" in your command? Do you mean every string element of the string array must be of the same length?

Subject: a string, a string array and character array

From: Arthur Zheng

Date: 10 Dec, 2008 21:01:04

Message: 11 of 24

Hi,
"String array" is not restricted to Mex routines. If you type "doc knnclassify", you can see "GROUP can be a numeric vector, a string array, or a cell array of strings."


Walter Roberson <roberson@hushmail.com> wrote in message <5FV%k.50213$zQ3.23530@newsfe12.iad>...
> Arthur Zheng wrote:
> > Let's talking within the range of matlab. What is the difference between "a string"
> > and "a string array"?
>
> "string array" is used, as best I can see, only in discussions of Mex routines,
> where it is "an mxArray having the mxCHAR_CLASS class", which is the same thing
> as a "character array", the term used in the rest of Matlab.

Subject: a string, a string array and character array

From: someone

Date: 10 Dec, 2008 21:38:03

Message: 12 of 24

"Arthur Zheng" <hzheng7@gatech.edu> wrote in message <ghpa7e$ihb$1@fred.mathworks.com>...
> NZTideMan <mulgor@gmail.com> wrote in message <41f10df9-2d98-4394-845b-f2815691f805@v39g2000pro.googlegroups.com>...
> > On Dec 11, 8:25=A0am, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> > > Let's talking within the range of matlab. What is the difference between =
> > "a string" and "a string array"?
> >
> > Easiest to explain with an example. Try this:
> > str=3D'Hello World'; % a string
> > stra=3Dstr2mat('Hello','World'); % a string array
> >
> > size(str) gives 1 11, in other words a row vector
> > size(stra) gives 2 5, in other words a matrix or "string array"
> > So a string array is simply some rows of strings (see Walter's post
> > for a definition).
> ----------------------------------------------------------------------
> What is "3D" in your command? Do you mean every string element of the string array must be of the same length?

It seems some newsgroup readers turn "= " into "=3D" for some reason.
You can see this behavior on several other threads of this newsgroup.

Subject: a string, a string array and character array

From: Arthur Zheng

Date: 10 Dec, 2008 22:02:03

Message: 13 of 24

In my understand, can I summarize as the following example:

1. This is a string: str='This is a string', which is also a character array, right?

2. This is a cell array of strings: strcell = {'This', 'is', 'Cellarray', 'of strings'};

3. This is a string array: stra = str2mat('Hi','World'); We must use str2mat function to do the padding in order to may the length of 'Hi' and 'world' the same.

Please comment on my examples. Thank you all.

Subject: a string, a string array and character array

From: NZTideMan

Date: 10 Dec, 2008 22:33:07

Message: 14 of 24

On Dec 11, 11:02=A0am, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> In my understand, can I summarize as the following example:
>
> 1. This is a string: =A0str=3D'This is a string', which is also a charact=
er array, right?
>
> 2. This is a cell array of strings: strcell =3D {'This', 'is', 'Cellarray=
', 'of strings'};
>
> 3. This is a string array: =A0 stra =3D str2mat('Hi','World'); =A0We must=
 use str2mat function to do the padding in order to may the length of 'Hi' =
and 'world' the same.
>
> Please comment on my examples. Thank you all.

You've got it, buster!!

Subject: a string, a string array and character array

From: Arthur Zheng

Date: 10 Dec, 2008 22:43:02

Message: 15 of 24

NZTideMan <mulgor@gmail.com> wrote in message <5112e766-e8e5-464f-976b-1c37525d1973@l33g2000pri.googlegroups.com>...
> On Dec 11, 11:02=A0am, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> > In my understand, can I summarize as the following example:
> >
> > 1. This is a string: =A0str=3D'This is a string', which is also a charact=
> er array, right?
> >
> > 2. This is a cell array of strings: strcell =3D {'This', 'is', 'Cellarray=
> ', 'of strings'};
> >
> > 3. This is a string array: =A0 stra =3D str2mat('Hi','World'); =A0We must=
> use str2mat function to do the padding in order to may the length of 'Hi' =
> and 'world' the same.
> >
> > Please comment on my examples. Thank you all.
>
> You've got it, buster!!

Thank you, NZTideMan

Subject: a string, a string array and character array

From: Steve Amphlett

Date: 10 Dec, 2008 23:25:04

Message: 16 of 24

"Arthur Zheng" <hzheng7@gatech.edu> wrote in message <ghpglm$1j0$1@fred.mathworks.com>...
> NZTideMan <mulgor@gmail.com> wrote in message <5112e766-e8e5-464f-976b-1c37525d1973@l33g2000pri.googlegroups.com>...
> > On Dec 11, 11:02=A0am, "Arthur Zheng" <hzhe...@gatech.edu> wrote:
> > > In my understand, can I summarize as the following example:
> > >
> > > 1. This is a string: =A0str=3D'This is a string', which is also a charact=
> > er array, right?
> > >
> > > 2. This is a cell array of strings: strcell =3D {'This', 'is', 'Cellarray=
> > ', 'of strings'};
> > >
> > > 3. This is a string array: =A0 stra =3D str2mat('Hi','World'); =A0We must=
> > use str2mat function to do the padding in order to may the length of 'Hi' =
> > and 'world' the same.
> > >
> > > Please comment on my examples. Thank you all.
> >
> > You've got it, buster!!
>
> Thank you, NZTideMan

Blurred, misty vision applies here...

In the olden days of ML, all data were doubles. But a row matrix could be assigned a "string" type, which meant that those doubles could/should/(?) be treated as ASCII characters and the row itself as a string.

I think. Or something like this. I've written MEX code to take "string" rhs[] arguments and convert them into strings (they still work).

The move to different data types has made this confusion more confusing.

Subject: a string, a string array and character array

From: Rune Allnor

Date: 11 Dec, 2008 06:29:27

Message: 17 of 24

On 10 Des, 21:12, Walter Roberson <rober...@hushmail.com> wrote:
> Rune Allnor wrote:
> > On 10 Des, 18:49, Walter Roberson <rober...@hushmail.com> wrote:
> >> 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,
> > The OP is clearly a newbie. I think it is premature to
> > start splitting hairs at this level.
>
> I disagree.

About what? That the OP is a Newbie or that it is premature to
start splitting hairs at this level? Well, when trying to enlighten
somebody at the newbie level, that is.

> You gave an authoritative-sounding answer that was
> wrong for Matlab (which does not have negative character values)
> and was wrong for the C++ language that you were importing the semantics of:

That was not the point. The point was to explain the difference
between numerals and strings. With newbies I usually bend the
details, which tend to obfuscate, to paint the big picture.
16 bit character types make sense when the guy comes back and
asks for extended character sets, but not before.

And I would certainly not hit a newbie in the head with the C
or C++ standards. There is a difference between enlightening
newbies and showing off.

Rune

Subject: a string, a string array and character array

From: Rune Allnor

Date: 11 Dec, 2008 06:59:30

Message: 18 of 24

On 10 Des, 21:12, Walter Roberson <rober...@hushmail.com> wrote:
> Rune Allnor wrote:

> >>> 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.
> > I suppose you can read? That you are familiar with the
> > lexical sorting of words? And that you have some at least
> > peripherical knowledge of the ASCII (or ANSI) character
> > sets?
> > As for programming languages, the above is how strings
> > work in C++.
>
> "Abc" and "abc" are, in C++, string literals [lex.string],http://www.kuzbass.ru:8086/docs/isocpp/lex.html#lex.string
> and string literals do NOT behave in the way you described.

Correct. But the data type std::string does.

std::string s;
s = std::string("abc") + std::string("def");

will work as I described. Think of the above as a type cast
(it isn't, but in the context it serves the same function).

> in
> which 'A' and 'a' would NOT compare as equal.

Where did I say they would?

Rune

Subject: a string, a string array and character array

From: Walter Roberson

Date: 11 Dec, 2008 18:38:54

Message: 19 of 24

Rune Allnor wrote:
> On 10 Des, 21:12, Walter Roberson <rober...@hushmail.com> wrote:
>> Rune Allnor wrote:
>
>>>>> 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.

>>> As for programming languages, the above is how strings
>>> work in C++.

>> and string literals do NOT behave in the way you described.
 
> Correct. But the data type std::string does.
 
> std::string s;
> s = std::string("abc") + std::string("def");
 
> will work as I described.

You mentioned two behaviours: string appending, and that for some
operations '"Abc" and "abc" are equivalent'. String appending is a
trivial operation that I am not concerned about. I am, though, looking
for ISO 14882 defined operations in which "Abc" and "abc" are required
to be somehow equivalent. Citation please! Or a citation that in
C++ that std::string specifically (or by inheritance from some other level of
behaviour) that "lowercase and uppercase letters have different numerical
values but the same ordinal value". What do you mean by saying that those
two strings are "equivalent" ?

I haven't said that you are wrong about that yet, but I am saying that I am
looking at the text of the C++ standard itself and I have not been able to find
any -requirement- that for -any- purpose "Abc" and "abc" are to somehow be treated
as "equivalent". I do see the possibility of two distinct characters comparing as
equal through the traits:: methods that I mentioned, but no -requirement-, so it
appears to me to be down to a matter of Locale. Certainly in terms of POSIX locales
it would be possible to construct a local in which particular upper and lower case
letters are to be considered to sort as equivalent, but the fact that [lib.strings]
has the -flexibility- to allow for such things is not the same as saying that
such things -must- be so as was implied by your posting: you did not say
that upper and lower-case characters *could* have the same ordinal value,
you said that they *do* have the same ordinal value... and I cannot seem to
find any C++ requirement to that effect.



--
.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)?

Subject: a string, a string array and character array

From: Rune Allnor

Date: 11 Dec, 2008 18:58:55

Message: 20 of 24

On 11 Des, 19:38, Walter Roberson <rober...@hushmail.com> wrote:
> Rune Allnor wrote:
> > On 10 Des, 21:12, Walter Roberson <rober...@hushmail.com> wrote:
> >> Rune Allnor wrote:
>
> >>>>> 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.
> >>> As for programming languages, the above is how strings
> >>> work in C++.
> >> and string literals do NOT behave in the way you described.
> > Correct. But the data type std::string does.
> > std::string s;
> > s = std::string("abc") + std::string("def");
> > will work as I described.
>
> You mentioned two behaviours: string appending, and that for some
> operations '"Abc" and "abc" are equivalent'. String appending is a
> trivial operation that I am not concerned about. I am, though, looking
> for ISO 14882 defined operations in which "Abc" and "abc" are required
> to be somehow equivalent. Citation please!

Basic English (and any other language using the latin alphabet):
Do you sort words on whether the words are written with uppercase
or lowercase letters? I'd bet that in 99.99% of the case you don't.
The order of how the strings "Abc" and "abc" appear in a sorted
sequence is arbitrary (or 'implementation dependent', in C/C++ lingo).

> Or a citation that in
> C++ that std::string specifically (or by inheritance from some other level of
> behaviour) that "lowercase and uppercase letters have different numerical
> values but the same ordinal value". What do you mean by saying that those
> two strings are "equivalent" ?

That the characters 'a' and 'A' have different ASCII (or
equivalent) values, but serve the same function. At least
in Norwegian (and I suspect, in English) the exact spelling
of a word depends on factors like at what position in the
sentence the word appears: The first word in a sentence is
always written with capital first letter. The meaning of
the word doesn't change by the capital first letter, nor
does the lexicographic sorting order of the words in the
sentence.

I suppose you don't demand refernces to such trivial facts?

> you did not say
> that upper and lower-case characters *could* have the same ordinal value,
> you said that they *do* have the same ordinal value... and I cannot seem to
> find any C++ requirement to that effect.

That's because there is a difference between C++ and the
real world: It's not the C++ standard (or even a Mathworks
Tech Note) that defines the ordering of the Latin alphabet:
Both the letters 'a' and 'A' preceed the letters 'b' and 'B',
which in turn prceed the letters 'c' and 'C', etc.

I am sure you have heard at one point or another that there
is no defined order between uppercase and lowercase forms
of the same letter. So the ordering of the strings "abc"
and "Abc" is undefined, which in turn means that the strings
are equivalent from a srting perspective. Were they words,
their lexical meaning would also be equivalent.

If you want further discussions on basic spelling, please
check with your local primary school.

Rune

Subject: a string, a string array and character array

From: Walter Roberson

Date: 11 Dec, 2008 19:00:41

Message: 21 of 24

Arthur Zheng wrote:
> In my understand, can I summarize as the following example:

> 3. This is a string array: stra = str2mat('Hi','World');

You should pretty much discard the term "string array" and instead use "character array".
Everything that you are calling "string array" is just a character array.
stra = ['Hi '; 'World'];

> We must use str2mat function to do the padding in order to may the length of
> 'Hi' and 'world' the same.

Or do it by hand. Or use

stra = char({'Hi', 'World'});

str2mat has been replaced by newer functionality and will be removed in some future
matlab version.

--
.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)?

Subject: a string, a string array and character array

From: Walter Roberson

Date: 11 Dec, 2008 20:35:20

Message: 22 of 24

Rune Allnor wrote:
> If you want further discussions on basic spelling, please
> check with your local primary school.

You have persisted in making demeaning comments about my ability to read
or know basic spelling rules; such comments are unnecessary, irrelevant,
and do not reflect well upon you.


Early in this thread you wrote,

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

And I replied that,

>>> Urrr, I've never encountered that definition of "string" before.

You responded that,

>> As for programming languages, the above is how strings
>> work in C++.


Strings either -do- or -do not- indeed work in the described way
in C++. If they -do- work in the manner described, then the described
behaviour ought to be locatable somewhere in the C++ Standard; I cannot
find that behaviour required anywhere in the C++ Standard.

In the most recent reply, you write that,

> It's not the C++ standard (or even a Mathworks
> Tech Note) that defines the ordering of the Latin alphabet:

and that,

> The order of how the strings "Abc" and "abc" appear in a sorted
> sequence is arbitrary (or 'implementation dependent', in C/C++ lingo).

Do I understand correctly that you are now withdrawing your claim
that the described behaviour is how strings *do* work in C++, and that
instead you are saying that the described behaviour is one of the
ways that strings are -permitted to- behave in C++ ?

I certainly have no disagreement that in C++ it is possible to construct
a string class and sort method that behaves in the manner you describe,
upon supplying appropriately configured trait:: tables -- but it is not
the normal behaviour in C++ for the ASCII or ANSI character sets you
referenced earlier. See
http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html
section 7.3.2 subsection "LC_COLLATE Category in the POSIX Locale"
(which is just before section 7.3.3)

Subject: a string, a string array and character array

From: Rune Allnor

Date: 11 Dec, 2008 20:52:14

Message: 23 of 24

On 11 Des, 21:35, Walter Roberson <rober...@hushmail.com> wrote:
> Rune Allnor wrote:
> > If you want further discussions on basic spelling, please
> > check with your local primary school.
>
> You have persisted in making demeaning comments about my ability to read
> or know basic spelling rules; such comments are unnecessary, irrelevant,
> and do not reflect well upon you.
>
> Early in this thread you wrote,
>
> >>>> 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).
>
> And I replied that,
>
> >>> Urrr, I've never encountered that definition of "string" before.

If you read my first post - where my goal still was to enlighten
the OP - carefully, you will see that I

a) Edited out the OPs reference to matlab
b) Never mentioned C, C++ or any other programming language.

My goal was to help the OP understand the different contexts
and semantics of numerical and literal data types. I even
explicitly mentioned this in one or two replies to you.

Then you start picking nits about standards, definitions and
all sorts of totally irrelevant questions (from the OPs POV)
that are not at all helpful to the discussion.

> You have persisted in making demeaning comments about my ability to read
> or know basic spelling rules;

Correct.

> such comments are unnecessary, irrelevant,

Not inasmuch as you first of all did not understand the context
of the OP's question (and thus my first answer), as well as that
you consistently have disregarded my explanations of the context
in which I provide my answers to the OPs questions.

> and do not reflect well upon you.

Right... "let him throw the first stone..." From Your signature:

> signature note: I am now avoiding replying to unclear or ambiguous postings.

...as if anybody who posts here do so to get *Your* particular
response...

Just answer the posts You find worthy of Your attention and
ignore the rest. Everybody else does.

Rune

Subject: a string, a string array and character array

From: Walter Roberson

Date: 12 Dec, 2008 00:35:34

Message: 24 of 24

Rune Allnor wrote:

> From Your signature:
 
>> signature note: I am now avoiding replying to unclear or ambiguous postings.

> Just answer the posts You find worthy of Your attention and
> ignore the rest. Everybody else does.

In the time frame leading up to my using my current signature, I was posting many
researched responses. That was taking a lot of my time: I was down to about 5 1/2 hours
of sleep a night (instead of 9) due to the time I was spending researching and answering
questions. An increasing number of people were relying on me for more and more complicated
problem analysis, and the number of people expecting me (personally) to supply them with
extensive code had risen sharply. The efforts I was putting in and the requests made of me
were physically and mentally unsustainable, and I literally got sick because of it.

I am working with a doctor to get my body back in shape, but it was clear to me that
I would also have to change the situation or it would continue to re-occur and
probably worsen. I reviewed the work I was doing, and realized that the part of it that
was taking the majority of time and effort for me was in replying to ambiguous and
unclear postings -- efforts researching the -possible- meanings of the postings, and
writing up responses that listed the possible meanings and the solutions to each of the
possibilities. As that was what was wearing me down the most, it is the part that I
had to cut back on the most in order to survive.


Perhaps the wording I used somehow comes across as a moral judgment on postings. It
isn't a moral statement, merely a factual one: questions that are ambiguous or unclear
are (generally) beyond what I can currently handle (especially in volume.)

The other three lines of my signature describe points that people can consider in
order to write better questions. When people write better questions, a greater
variety of people tend to respond, which reduces the load not only upon me personally
but also upon all of the regulars.


I don't -like- having to skip responding to interesting-looking postings that I can
see will take a lot of effort to discover the -real- question behind. I don't
even -like- having to skip routine questions that I know that other people are also
likely to skip as being too much effort to educate the poster. I would *prefer* to see
all -reasonable- questions answered. That doesn't happen in practice, though. I answer
many postings because there are many postings that other people leave unanswered.
Regrettably, the load of otherwise- unanswered postings exceeds what I am able to
handle by myself.

I do what I can, but what I can currently sustain is much less than what I had been
doing previously.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us