String (computer science): Difference between revisions

Content deleted Content added
m -/Talk
m '\0' != '0'
Line 5:
=== Representations ===
 
A common representation is an [[array]] of characters. The length can be stored implicitly by using a special terminating character (often [[NUL]]) (the programming language [[C programming language|C]] uses this convention), or explicitly (for example by treating the first byte or bytes of the string as its length, a convention used in [[Pascal programming language|Pascal]]).
 
Here is a NUL terminated string stored in a 10 [[Integral data types|byte]] buffer.
NUL is the name for the character in [[ASCII]] which has the numeric value of zero.
In the C language, NUL is called '\0'.
 
<PRE>
x x x x x x x x x x
F R A N K \0 k f f w
x x x x x x x x x x
</PRE>
The above example is how "FRANK" would look in a 10 byte NUL terminated string. Characters after the \0 do not form part of the representation.
 
Of course, other representations are possible. Using [[tree]]s and [[list]]s make it easier to insert characters in the middle of the string.