Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

String: Difference between revisions

From Coderwiki
new
 
link to Collection
 
(One intermediate revision by the same user not shown)
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 [[list]] of [[Char|chars]]. The size and values of these [[char]] elements depends on the [[character set]] the programming language uses.
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 arrays. They store both a [[List size and capacity|size and capacity]].
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 ==
Languages like [[Rust]] have many different string [[Data type|types]] for different use-cases.<blockquote>See [[Rust string]] for more info.</blockquote>
Languages like [[Rust]] have many different string [[Data type|types]] for different use-cases.<blockquote>See [[Rust string]] for more info.</blockquote>
== String methods ==
There are various [[Method|methods]] you can call on strings. These include (but are not limited to):
* [[String length]]
* [[String position]]
* [[String substring]]
* [[String concatenation]]


== Examples of strings ==
== Examples of strings ==

Latest revision as of 07:59, 13 August 2025

A string in programming generally represents text formatted with a specific character set.

Most 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 source

String 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 source

Languages 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.

Languages like Rust have many different string types for different use-cases.

See Rust string for more info.

String methods

edit edit source

There 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 source
3.1415926535898
true
57
'A'