A string in programming is simply text stored as data: a sequence of characters such as letters, digits, spaces, and symbols. When you write a name, a sentence, or even a phone number that you do not plan to do math with, you store it as a string. You usually wrap a string in quotation marks so the language knows it is text rather than a command or a number. Strings are one of the most common things you handle in code, and getting comfortable with them early makes everything else easier. Here is what a string really is and how to work with one.
How text is stored
A computer ultimately stores everything as numbers, so each character in a string is mapped to a number behind the scenes through a standard encoding. You almost never deal with that directly. From your point of view, a string is just an ordered run of characters, and the order matters: the word cat and the word act contain the same letters but are different strings.
Because a string is ordered, the language can tell you its length, fetch the first or last character, and pull out a slice from the middle. These small abilities add up. Validating a form, formatting a date, or building a message to show a user is all string work.
If the broader idea of how values are categorized is still fuzzy, our explainer on what a data type is sets the stage nicely.
What you can do with strings
Most languages give strings a rich set of built-in operations. You rarely have to build these yourself.
| Operation |
What it does |
Everyday use |
| Concatenation |
Joins two strings end to end |
Building a full name from first and last |
| Length |
Counts the characters |
Checking a password is long enough |
| Slice |
Extracts part of the string |
Grabbing an area code |
| Search |
Finds text inside a string |
Detecting a keyword |
| Replace |
Swaps one piece of text for another |
Cleaning up user input |
| Case change |
Converts to upper or lower case |
Making comparisons consistent |
Joining strings is so common it has a name, concatenation, and most languages also offer templates that let you drop variables straight into a sentence.
Strings vs numbers
The trap that catches almost every beginner is treating a string like a number. The value "5" wrapped in quotes is text, not the number five. Try to add "5" and "5" and many languages will glue them into "55" rather than giving you ten. To do arithmetic you first convert the string into an actual number.
The reverse happens too: a real number turned into a string is handy for display but can no longer be added or multiplied until you convert it back. Knowing which form you hold at any moment prevents a huge share of early bugs. Our guide to what a syntax error is covers the related slip of forgetting a closing quote.
Common mistakes
- Forgetting the quotes. Text without quotes is read as code or a variable name, which usually triggers an error.
- Mismatched quote marks. Opening with one style and closing with another leaves the string unterminated.
- Doing math on quoted numbers. Convert a numeric string to a number before adding, or you will concatenate instead.
- Assuming case does not matter. Apple and apple are different strings; normalize case before comparing.
FAQ
What is the difference between a string and a character?
A character is a single symbol, while a string is a sequence of zero or more characters. In many languages a single character is just a very short string.
Why are numbers sometimes stored as strings?
Things like phone numbers, postal codes, and ID numbers are not used for math and may start with a zero, so storing them as text keeps them intact.
How do I join two strings?
Most languages use a plus sign or a dedicated join operation, and many also support templates that insert variables directly into a string.
Are strings hard to learn?
No. Strings are one of the first data types most people meet, and a handful of operations cover the vast majority of real work.
Where to go next
Ground yourself with What Is a Data Type in 2026, learn how true-or-false values differ in What Is a Boolean in 2026, and decode common errors in What Is a Syntax Error in 2026.