Go Down

Topic: String to int (Read 856 times) previous topic - next topic

michael_x


Quote
working with string instead of char* is already some overkill,

Did you mean, "working with String instead of char* is already some overkill,"?


Thanks for giving me the chance to clarify:

lowercase "string" is just a confusing word for a char array.

A "String object, which gives you more functionality at the cost of more memory" is a thing I'd prefer to avoid on a small Arduino UNO, unless this additional functionality is really what you need and don't want to implement in plain c. That is more than charAt() and toCharArray() methods  ;)


AWOL

Quote
lowercase "string" is just a confusing word for a char array.

Nothing confusing there; a string is a char array that is null-terminated, but a char array doesn't have to contain a string.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

michael_x

#7
May 02, 2012, 01:20 pm Last Edit: May 02, 2012, 08:55 pm by michael_x Reason: 1

... a string is a char array that is null-terminated, but a char array doesn't have to contain a string.


You're right, point taken.

string sample="Some Sample Text"; // error: 'string' does not name a type  ;)
byte ba[] = {50, 100, 200, 0};    // usually omitting "unsigned" is laziness,
                                 // but for non-character chars, one might choose this type if possible
                                 // ( signed byte is not allowed, though )

AWOL

Quote
usually omitting "unsigned" is laziness,

In the case of "byte", not so - the type is defined to be unsigned, so adding an extra "unsigned" would be tautological.
If the array were of type "char", then yes, omitting an "unsigned" could be deemed lazy (but not by many).

Code: [Select]
typedef uint8_t byte;
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Code: [Select]
string sample="Some Sample Text";
This string is a completely different beast, and only an asshole would have chosen such a generic term, that already had a quite well defined (but different) meaning, for a class name.

Go Up