Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Techniques

Similar presentations


Presentation on theme: "Programming Techniques"— Presentation transcript:

1 Programming Techniques
Keywords String Operators, length, substring, upper, lower. Programming Techniques String Manipulation

2 String Operators String Handling Objectives
BEGINNER: Explain basic string operators. ADVANCED: Make use of programming to aid character set conversion. EXPERT: Develop a program that makes use of string manipulation. String Handling To get the length of a string: stringname.length To get a substring: stringname.substring(startingPosition, numberOfCharacters) Converting Cases: stringname.upper stringname.lower Starter activity ASCII Conversion: ASC (character) CHR (asciinumber)

3 String Operators Objectives
BEGINNER: Explain basic string operators. ADVANCED: Make use of programming to aid character set conversion. EXPERT: Develop a program that makes use of string manipulation. LEN(“Hello”) can be also written as “Hello”.length and it is 5. SUBSTRING(“Hello”,1,3) would start with the 2nd character and extract 3 characters ”ello”, can also be written as MID(“Hello”,1,3) We assume the first character has an index 0. UPPER(“Hello”) becomes “HELLO”, can be also written as “Hello”.upper LOWER(“Hello”) becomes “hello”, can be also written as “Hello”.lower Starter activity

4 Character Set Conversion
Objectives BEGINNER: Explain basic string operators. ADVANCED: Make use of programming to aid character set conversion. EXPERT: Develop a program that makes use of string manipulation. CHR(98) – “b” CHR(66) – “B” Python example to show the link between characters and their ASCII table indices. Starter activity

5 Escape/Whitespace Characters
Objectives BEGINNER: Explain basic string operators. ADVANCED: Make use of programming to aid character set conversion. EXPERT: Develop a program that makes use of string manipulation. Escape characters are strings with a special meaning. They are usually denoted by “\” appearing in front of them. E.g. “\n” is not just “n” but a “new line” – this forces a computer to move to the next line. “\t” is a TAB – usually 4 or 5 spaces. It is used to line up columns of data. Both “\n” and “\t” are “whitespace” characters – they are not text but rather breaks between text. “ “ – space is another one. E.g. OUTPUT “Name” + “\t” + “Age” + “\n” OUTPUT “Bob” + “\t” + “12” + “\n” OUTPUT “Nora” + “\t” + “13” + “\n” Will display: Name Age Bob 12 Nora 13 Starter activity

6 Additional uses of escape characters
Objectives BEGINNER: Explain basic string operators. ADVANCED: Make use of programming to aid character set conversion. EXPERT: Develop a program that makes use of string manipulation. We put literal values of strings in speech marks (quotations or actually foot and inch marks), e.g. “John” or ‘John’. The computer knows that the first speech mark (apostrophe) starts the string and the next speech mark ends the string. However, it is possible to have an apostrophe inside a string, e.g. ‘It’s ok’ – that will confuse the computer as it will think that we terminated our string of ‘It’ and it doesn’t know how to read “s ok’” – and will show an error. If we put an escape forward slash in front of the apostrophe it will know to treat it like a regular letter, e.g. ‘It\’s ok’ – is ok! If we have “\” inside our strings, e.g. in a date, we need to escape it like so “\\”. E.g. OPEN FILE “c:\\testing\\test.txt” “The use of \\, the forward slash in IT is very interesting.” Starter activity

7 Task Objectives BEGINNER: Explain basic string operators. ADVANCED: Make use of programming to aid character set conversion. EXPERT: Develop a program that makes use of string manipulation. A school generates a students username from the following: The first 3 letters of their surname in uppercase The first 2 letters of their first name in uppercase Year they start e.g. if Mathew Fish started in 2018 his username would be: FISMA2018 Write an algorithm and a program that generates a username using these rules. Starter activity


Download ppt "Programming Techniques"

Similar presentations


Ads by Google