Content deleted Content added
m '\0' != '0' |
No edit summary |
||
Line 1:
The
A common representation is an [[array]] of characters. The length can be stored implicitly by using a special terminating character (often [[NUL]], ASCII code 0)
Here is an example of a NUL terminated string stored in a 10 [[Integral data types|byte]] buffer
<table cellspacing="0" celpadding="2" border="1">
<tr><td>F</td> <td>R</td> <td>A</td> <td>N</td> <td>K</td> <td> </td> <td>k</td> <td>f</td> <td>f</td> <td>w</td> </tr>
<tr><td>46</td> <td>52</td> <td>41</td> <td>4E</td> <td>4B</td> <td>00</td> <td>6B</td> <td>66</td> <td>66</td> <td>77</td> </tr>
</table>
The length of a string in the above example 5 characters, but note that it occupies 6 bytes. Characters after the terminator do not form part of the representation; they may be either part of another string or just garbage.
Of course, other representations are possible. Using [[tree]]s and [[list]]s make it easier to insert characters in the middle of the string.▼
▲Of course, other representations are possible. Using [[tree]]s and [[list]]s
=== String Processing ===▼
== String manipulation ==
Two most common operations on the strings are [[string search algorithm|searching]] and sorting. Because the practical value of string representation is enormous, many more-or-less efficient algorithms were discovered.
Advanced string algorithms often employ complex mechanisms and data structures, among them [[suffix tree]]s, [[finite state machine]]s.
Strings are such a useful datatype that several languages have been designed in order to make string processing applications easy to write. Examples include:
* [[awk]]
* [[Icon programming language|Icon]]
Line 29 ⟶ 37:
* [[sed]]
* [[SNOBOL]]
Many [[UNIX]] utilities perform simple string manipulations and can be used to easily program some powerful string processing algorithms. Files and finite streams may be viewed as strings.
|