In computer programming, a string is a type of data that may contain letters, numbers, and symbols, and that is stored as a sequence of text.
Strings are stored in a specific sequence. For example, the string “Mary had a little lamb” is stored exactly as it is typed, and a search for the string “lamb little Mary” would not find the stored string unless an advanced algorithm, such as those used by search engines, was used to find partial matches.
Websites use strings to store things like usernames, encrypted passwords, and the text content of a blog post. Virtually all of the text you read on the web is stored as a string in a database server somewhere.
While strings can be used to hold many types of symbols, letter, and numbers, in many cases the content that can be used to fill a specific string may be limited. For example, if you use WordPress to administer a website, the status of every post is stored as a string, with one of eight possible values assigned to the string: “publish”, “pending”, “draft”, “private”, “trash”, “auto-draft”, “inherit”, and “future”. Since the software itself assigns the value to this string, it isn't possible to change the value of this string to anything other than one of the predefined values unless you do so manually by accessing the database, in which case the post will break and not be rendered on the site.
Frequently Asked Questions
What letters, symbols, and numbers can a string include?
In most programming languages strings are the wild card data type that can be used to hold information and values that don't fit inside of any other data types. This means that virtually any letter, number, or symbol can be stored in a string. However, when using strings to store information, think about how that information will be used. For example, if you're storing data that will later be processed by a browser, think about the way the browser will interpret symbols like “&” and “<” which may not render correctly when rendered by the browser's HTML engine.
What is an empty string?
How are strings used to locate information?
Search engines compare search terms to the strings of information stored in their index. Typically, they will break the search terms into several substrings and compare each substring to the strings of information stored in their index, checking for both partial and complete matches. Complex algorithms are then used to determine which matches are the most relevant.