String: Difference between revisions
More actions
add methods section |
link to Collection |
||
| Line 8: | Line 8: | ||
== Representation == | == Representation == | ||
String are represented differently across different [[Programming language|programming languages]], but they are usually made up of an [[array]] or [[ | String are represented differently across different [[Programming language|programming languages]], but they are usually made up of an [[array]] or [[collection]] of [[Char|chars]]. The size and values of these [[char]] elements depends on the [[character set]] the programming language uses. | ||
== Null-termination == | == Null-termination == | ||
Languages like [[C]] do not store the length of an [[array]]. Instead, [[Data type|data types]] like strings are ended whenever a [[Null termination|null terminator]] is reached. This is usually the <code>\0</code> character. | Languages like [[C]] do not store the length of an [[array]]. Instead, [[Data type|data types]] like strings are ended whenever a [[Null termination|null terminator]] is reached. This is usually the <code>\0</code> character. | ||
Other languages with proper [[array]] types instead store strings as [[List|lists]] or other dynamic | Other languages with proper [[array]] types instead store strings as [[List|lists]] or other dynamic [[Collection|collections]]. They store both a [[Collection size|size]] and [[Collection capacity|capacity]]. | ||
== String types == | == String types == | ||
Latest revision as of 07:59, 13 August 2025
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'