strings and character sequences?

Pages: 12
Jun 6, 2010 at 6:44am
Why would you ever prefer character sequences above strings?

Xander
Jun 6, 2010 at 6:49am
A string is a character sequence.
Jun 6, 2010 at 6:52am
If by string you mean the string class, it's because they're dynamically allocated, have all the necessary search, modification, and segment accessing functions built in, and unless you do something quite stupid you'll never have any memory problems with them..

-Albatross
Jun 6, 2010 at 6:18pm
If by a character sequence, you mean a char *, then it is typically considered bad practice to use them at all in C++.

However, you sometimes need to use char *'s when interfacing with legacy code. In these cases, I recommend using strings for the bulk of the program, and then using the string::c_str() function to get a char * representation of the string. If the lagacy gives you a char *, pass it immediately into a string constructor. If you follow these rules, you should be pretty safe.
Jun 6, 2010 at 6:52pm
... and then using the string::c_str() function to get a char * representation of the string.
const char*
Jun 6, 2010 at 8:22pm
Maybe the OP means something like std::vector<char> when he says "character sequences". If I didn't really want a string, I'd rather store my data to an std::vector<char> because doing so saves me the cstr representation and the operations made on it every time I change my data.
Jun 7, 2010 at 12:53pm
??

Is it not pretty obvious that he means a char array over string objects? I'm also assuming that helios knew this and was just being picky about the use of terms, which has made you all overlook the obvious?
Jun 7, 2010 at 1:15pm
mcleano wrote:
Is it not pretty obvious that he means a char array over string objects?

Not really. At least not to me.
Last edited on Jun 7, 2010 at 1:16pm
Jun 7, 2010 at 2:35pm
I'm also assuming that helios knew this and was just being picky about the use of terms
>:-)
Jun 7, 2010 at 2:52pm
A string is a character sequence (much like every month has (at least) 28 days) but a character sequence isn't necessarily a string. In c++ you could say it like this:

1
2
class CharacterSequence {/*...*/};
class String: public CharacterSequence {/*...*/};

EDIT: A string is a character sequence that has some meaning in a linguistic context.
Last edited on Jun 7, 2010 at 2:56pm
Jun 7, 2010 at 2:54pm
Can you name a character sequence that can't be interpreted as a string?
Jun 7, 2010 at 2:57pm
A string does not need to have a "linguistic" context...

How about std::string str("12&=)&aglabrabb"); <- That´s a string, too...

btw; the original "string" is just an '\0' -terminated character sequence (AFAIK)...
Last edited on Jun 7, 2010 at 2:59pm
Jun 7, 2010 at 2:58pm
"asdf@#$%WG%FRE"

You can store it as a string but strictly speaking it isn't one.
Jun 7, 2010 at 3:00pm
It is...

EDIT: How About a DNS-String?...

The term string referes to a concatenation of "items"... just an order of "something"
Last edited on Jun 7, 2010 at 3:02pm
Jun 7, 2010 at 3:02pm
Ok, I'm not arguing anymore on this. We could do this all day and I can't afford it. Clearly, we have a different understanding of the meaning of the word "string".
Jun 7, 2010 at 3:05pm
Why don´t we take the global accredited meaning from a dictionay? We can derive the std::string´s meaning from it... Or just "ask" the creators of the stl how they came up with naming std::string std::string:P...
Jun 7, 2010 at 3:09pm
Well, since that is what you want...

http://en.wikipedia.org/wiki/String_%28computer_science%29

In mathematical logic, more precisely in the theory of formal languages, and in computer science, a string is a sequence of symbols that are chosen from a set or alphabet.
In computer programming, a string is, essentially, a sequence of characters. A string is generally understood as a data type storing a sequence of data values, usually bytes, in which elements usually stand for characters according to a character encoding, which differentiates it from the more general array data type. In this context, the terms binary string and byte string are used to suggest strings in which the stored data does not (necessarily) represent text.
Last edited on Jun 7, 2010 at 3:09pm
Jun 7, 2010 at 3:47pm
You are annuling your own argument with itself:
r0shi wrote:

In mathematical logic, more precisely in the theory of formal languages, and in computer science, a string is a sequence of symbols that are chosen from a set or alphabet.


In mathematical logic, more precisely in the theory of formal languages, and in computer science, a string is a sequence of symbols that are chosen from a set or alphabet.


You know that the character sets contain more than just the alphabet?!?!?...


r0shi wrote:
In computer programming, a string is, essentially, a sequence of characters. A string is generally understood as a data type storing a sequence of data values, usually bytes, in which elements usually stand for[b] characters according to a character encoding, which differentiates it from the more general array data type.[/b] In this context, the terms binary string and byte string are used to suggest strings in which the stored data does not (necessarily) represent text.



In computer programming, a string is, essentially, a sequence of characters. A string is generally understood as a data type storing a sequence of data values, usually bytes, in which elements usually stand for characters according to a character encoding, which differentiates it from the more general array data type. In this context, the terms binary string and byte string are used to suggest strings in which the stored data does not (necessarily) represent text.


Same as above... character does not only mean a-z and 1 to 0... It´s alsow a term for a symbol which includes any other characters in the set...


BTW:

Generally, string is a thin, flexible piece of rope or twine which is used to tie, bind, or hang other objects.
http://en.wikipedia.org/wiki/String <- The general thing...
Last edited on Jun 7, 2010 at 3:48pm
Jun 7, 2010 at 4:09pm
You know that the character sets contain more than just the alphabet?!?!?...
"Alphabet" means something different in this context.
Jun 7, 2010 at 4:29pm
I think, that his character set contains only letters from words and numbers...
Pages: 12