String (computer science): Difference between revisions

Content deleted Content added
No edit summary
Drj (talk | contribs)
clarified details of representation, linked to string processing languages
Line 1:
A string has special connotations in the world of [[computing]]. It isA literallygeneric name for a group[[datatype]] ofcommonly lettersfound "strung"in togethermany [[programming languages]]. The mostexact commonsemantics stringof isthe datatype vary from language to language but it usually has the "null-terminated"core semantics of represented a finite ordered sequence of [[character]]s (alsoa knowngroup asa nil-terminatedcharacters "strung" together, orhence 0-terminated)the stringname). It receivesmay thisalso namerefer basedto onstrings theof wayother itdatatypes storesother datathan characters (such as strings of numbers or vectors).
 
=== Representations ==
For instance, a program may want to receive input of variable length. It requests 10 [[Integral_data_types|bytes]] from the computer into which to store characters. It receives the data to store, and appends a 0 after the data to signify the end of the string.
 
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 uses this convention), or explicitly (for example by treating the first byte of the string as its length, a convention used in [[Pascal]]).
 
Here is a NUL terminated string stored in a 10 [[Integral_data_types|byte]] buffer.
 
<PRE>
Line 8 ⟶ 12:
x x x x x x x x x x
</PRE>
The above example is how "FRANK" would look in a 10 byte null-NUL terminated string. Characters after the 0 aredo not form ignoredpart byof the computerrepresentation.
 
Of course, other representations are possible. Using [[tree]]s and [[list]]s would make it easier to insert characters in the middle of the string.
 
=== String Processing ===
 
Strings are such a useful datatype that several languages have grown up that were designed in order to make string processing applications easy to right. Examples include:
An alternate mechanism defines the first character of the string to be the length of the string. This definition limits strings based on 8 bit bytes to a maximum length of 255 characters.
* [[SNOBOL]]
* [[Icon]]
* [[perl]]
* [[awk]]
* [[sed]]
 
Many [[UNIX]] utilities perform simple string manipulations and can be used to easily program some powerful string processing algorithms.
----
/Talk