Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Etymology of “String”

I was talking to my non-technical wife about my workday and she was confused as to why I was talking about strings. In her mind, a string is a piece of yarn or thread (I didn't tell her what I thought a thread was).

So it got me wondering...why do we use the vernacular "String" to mean "a character array"?

share|improve this question

marked as duplicate by Mark Trapp Nov 6 '11 at 9:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Possible duplicate of… and also dealt with in detail at… – Hugo Nov 6 '11 at 9:20
It's a universal term, it's not just for object-oriented languages. – Mike Baranczak Nov 6 '11 at 14:05

We inherited from Mathematics (like a lot of things).

From my days as a student doing Maths (I remember it being though my memory is fuzzy).

  • It means an ordered sequence of elements. Where each element belongs to a finite set.
share|improve this answer

A string is not an array of characters.

It is an array of codepoints. Codepoints are not characters. This is quite a complex topic, but the unfortunate fact is that "Array of characters" only works for Western Latin based scripts, and falls apart horrendously once you start dealing with more complex languages. If you're curious for more details, you can look into Unicode.

I believe that strings originated because a linked-list implementation would resemble pieces of string tied together to make the final product.

share|improve this answer
Context is pretty important here. A "string" can certainly mean an array of characters -- there are countless programs and libraries out there that represent strings precisely that way. That said, Unicode adoption and need for localization have steadily increased over the last two decades, and every programmer should now understand that a string may be more than just a char[]. – Caleb Nov 6 '11 at 7:03
"Why do some people walk on an escalator when it only saves them a few seconds?" Your answer: "It doesn't save them a few seconds. If the speed of the escalator is close to the speed of light and if your speed is also close to the speed of light, you won't save almost anything." It's great that you know the difference between characters and codepoints. – Jan Soltis Nov 6 '11 at 9:50

From this definition (one of many) of string: a necklace consisting of a number of beads, pearls, or the like threaded or strung on a cord.

Or possibly from the verb to string: to connect in or as in a line; arrange in a series or succession: "She knows how to string words together."

Which is probably where Loki's mathematical use of the word arises, and both perfectly match DeadMG's clarification of what a text string really is.

share|improve this answer
+1 for pointing out where mathematics etc. got their idea to use the word string... – Marjan Venema Nov 6 '11 at 8:56

Generally, string is a flexible piece of rope or twine which is used to tie, bind, or hang other objects.

My guess is that the term was simply derived from this, because a sequential array of text just resembles it, including its typical uses. As others said, there are many more meanings to the term in regard to computer science:

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and/or the length changed, or it may be fixed (after creation). A string is generally understood as a data type and is often implemented as a byte (or word) array that stores a sequence of elements, typically characters, using some character encoding. A string may also denote more general array data types and/or other sequential data types and structures; terms such as byte string, or more general, string of datatype, or datatype-string, are sometimes used to denote strings in which the stored data does not (necessarily) represent text.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.