CPS 1 - Spring, 1997 - Ramm 1/31/97 #7
- Announce
- Go over last Wednesday's quiz
Chapter 2. Text Manipulation and Algorithm Design
- STRING and INTEGER Data Types
- var
- x, y: string;
- a, b: integer;
- Also have REAL; will use later
- Other Operators for INTEGERS
- Arithmetic:
- +, -
- *, div
- Comparison:
- <, >
- <>, =
- Don't mix types!
- Compiler with stop in mixed arithmetic
- Program will fail on mixed I/O
- Examples
- Back to text: String FUNCTIONs
- Function Arguments
- Function Return Value
- Help manipulate strings
- Picking and choosing characters in a string.
- Copy (Substring) Function
- string := COPY(string, start, length);
- can get null string
- str := 'liberation';
- copy(str, 1, 3) ==> ___________
- copy(str, 5, 6) ==> ___________
- copy(str, 3, 5)+'e' ==> ___________
- Length Function
- length := LENGTH(string);
- can get 0
- str := 'liberation';
- length(str) ==> ___________
- Position Function
- position := POS(substring, string);
- get 0 if not found
- first occurrence
- str := 'liberation';
- pos('ration', str) ==> ___________
- pos('i', str) ==> ___________
- str2 := 'rat';
- pos(str2, str) ==> ___________
- pos(str, str2) ==> ___________
- Using Functions Within Functions
- str1 := 'industrial';
- str2 := 'du';
- copy(str1, pos(str2, str1), 4) ==> ___________
- str2 := 'du';
- copy(str1, pos('tr', str1), length(str1-pos('tr',str1)+1)
- Using the String Functions
- Example: Pig Latin
- He is a good cook.
- ehay siway away oodgay ookcay
- The teacher is coming
- hetay eachertay siway omingcay
-
piglatin.pas
-
piglatin2.pas
- Advanced Topic: Character Translation
The "CryptoQuote" Problem
translate.pas