String

In computer science, a string is a fundamental data type used to represent text, as opposed to numeric data types like integers or floating-point numbers. It contains a sequence or "string" of characters, which may include letters, numbers, symbols, and spaces.

In most programming languages, strings are enclosed in quotation marks to differentiate them from other data types, such as numbers or variable names. For instance:

name = "Peter"; // This is a string
age = "44";     // This is a string
ID = 123;       // This is a number

A computer programmer may compare strings to see if they match. For example, the following comparison checks if phrase1 and phrase2 are equal.

if (phrase1 === phrase2) {
  // Code to execute if the values are equal
}

The three equal signs in the comparison above check if the strings match AND if they are the same data type. For example, comparing the strings "12345" and "12345" would return TRUE, but comparing the string "12345" with the integer 12345 would return FALSE. Additionally, comparing any two non-identical strings, such as "12345" and "12344", would return FALSE.

A string's length is determined by counting its characters. Most programming languages have a string length" function (such as strlen() in PHP) that returns the length of a given string. In older programming languages (like C), strings are terminated with a marker called a null character (\0) to signify the end of the string in memory.

Modern programming languages provide various functions to evaluate and manipulate strings, such as finding substrings, providing close or "fuzzy" string matches, and replacing text. These types of string operations are fundamental to the operation of search engines and generative AI.

Updated December 18, 2024 by Per C.

quizTest Your Knowledge

Which of the following is not a type of evidence collected by digital forensics?

A
Email and text message timestamps
0%
B
Wi-Fi data packets intercepted by a packet sniffer
0%
C
Fingerprints on a keyboard or mouse
0%
D
GPS location information in EXIF metadata
0%
Correct! Incorrect!     View the Digital Forensics definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of String on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.