Lably
Skip to content

String (computer science)

Sequence of characters, data type

  • 20 min read
  • 9 chapters
  • 1 lab on Lably

Learn it on Lably

Depending on the programming language and precise data type used, a variable declared to be a string may either cause storage in memory to be statically allocated for a predetermined maximum length or employ dynamic allocation to allow it to hold a variable number of elements.

When a string appears literally in source code, it is known as a string literal or an anonymous string.

In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set called an alphabet.

Purpose

A primary purpose of strings is to store human-readable text, like words and sentences. Strings are used to communicate information from a computer program to the user of the program. A program may also accept string input from its user. Further, strings may store data expressed as characters yet not intended for human reading.

Example strings and their purposes:

  • A message like "file upload complete" is a string that software shows to end users. In the program's source code, this message would likely appear as a string literal.
  • User-entered text, like "I got a new job today" as a status update on a social media service. Instead of a string literal, the software would likely store this string in a database.
  • Alphabetical data, like "AGATGCCGT" representing nucleic acid sequences of DNA.
  • Computer settings or parameters, like "?action=edit" as a URL query string. Often these are intended to be somewhat human-readable, though their primary purpose is to communicate to computers.

The term string may also designate a sequence of data or computer records other than characters, like a "string of bits", but when used without qualification it refers to strings of characters.

Sign in to keep reading

8 more chapters are free with a Lably account.

More in Computer Applications