String
More actions
A string in programming generally represents text formatted with a specific character set.
Syntax
edit edit sourceMost programming languages indicate strings using double quotes " surrounding the string. For example:
"this is a string" "this is also a string" "4.321"
Representation
edit edit sourceString are represented differently across different programming languages, but they are usually made up of an array or collection of chars. The size and values of these char elements depends on the character set the programming language uses.
Null-termination
edit edit sourceLanguages like C do not store the length of an array. Instead, data types like strings are ended whenever a null terminator is reached. This is usually the \0 character.
Other languages with proper array types instead store strings as lists or other dynamic collections. They store both a size and capacity.
String types
edit edit sourceLanguages like Rust have many different string types for different use-cases.
See Rust string for more info.
String methods
edit edit sourceThere are various methods you can call on strings. These include (but are not limited to):
Examples of strings
edit edit source"pineapple" "3.1415926535898" "Paris, France" "01382 482659"
Non-examples of strings
edit edit source3.1415926535898 true 57 'A'