View
238
Download
0
Embed Size (px)
Citation preview
Created byZaheer Abbas Aghani
Lecture 13Lecture 13
STRINGS STRINGS PROCESSING PROCESSING
String (Definition)String (Definition) Computer terminology usually uses the term Computer terminology usually uses the term
“string” for the sequences of character.“string” for the sequences of character.
A Finite sequence of characters is called Strings.A Finite sequence of characters is called Strings.
OROR
Anything that contains more than one character Anything that contains more than one character struck together. struck together.
For-example “For-example “ThisThis” is a string.” is a string.
Storing StringsStoring Strings
Strings are stored in three types of Strings are stored in three types of structure:structure:
1)1) Fixed –length structures.Fixed –length structures.
2)2) Variable length structures with fixed Variable length structures with fixed maximumsmaximums
3)3) Linked structures.Linked structures.
Fixed –length structuresFixed –length structures In fixed length storage each line of strings is viewed as a In fixed length storage each line of strings is viewed as a
records, where all records have the same length i.e. where records, where all records have the same length i.e. where each record accommodates the same number of characters.each record accommodates the same number of characters.
For example we will assume that our records have length For example we will assume that our records have length 20 columns/characters then in memory strings will store as 20 columns/characters then in memory strings will store as follows:follows:
s t r i g s p r o c e s s i n g
T O B E O R N O TT O B E
s t r i g s
201 210
220
221 230 240
241 250 260
Variable Length storage with fixed Variable Length storage with fixed maximummaximum
The storage of variable length in memory cells The storage of variable length in memory cells with fixed max can be done in two general ways:with fixed max can be done in two general ways:
1.1. One can use a marker, such as two dollar sign ($One can use a marker, such as two dollar sign ($$), to signal the end of the string.$), to signal the end of the string.
2.2. One can list the length of the string--- as an One can list the length of the string--- as an additional item in the pointer arrayadditional item in the pointer array
s t r i g s
201 210
220
$ $
End of String
Fig: Records with sentinels
Variable length storage with Variable length storage with pointerpointer
20
10
2
s t r i n g p r o c e s s i n gs
Pointer
Fig: Records whose lengths are listed
Linked StorageLinked Storage For most extensive word processing For most extensive word processing
applications, strings are stored by means of applications, strings are stored by means of linked lists. linked lists.
Strings may be stored in linked list as follows. Strings may be stored in linked list as follows. Each memory cell assigned one character , and a Each memory cell assigned one character , and a link contained in the cell gives the address of the link contained in the cell gives the address of the cell containing the next character. For example cell containing the next character. For example following fig shows how “string” word would following fig shows how “string” word would appear in memory with one character per node.appear in memory with one character per node.
S t r i n g
Fig: Linked List
String ConstantsString Constants
Constant is a value that store once in memory & it cannot Constant is a value that store once in memory & it cannot be changed. be changed.
Many programming languages denotes string constant by Many programming languages denotes string constant by placing the string in single or double quotation marks.placing the string in single or double quotation marks.
For example: For example: ‘‘The End’ The End’ or or “The End” “The End” are string constants of are string constants of length 7.length 7.