Programming Techniques

Slides:



Advertisements
Similar presentations
Character and String definitions, algorithms, library functions Characters and Strings.
Advertisements

IT151: Introduction to Programming
Chapter 8 Characters and Strings Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
Introduction to Python
Chapter 2: Introduction to C++.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Tutorial 14 Working with Forms and Regular Expressions.
 Text Manipulation and Data Collection. General Programming Practice Find a string within a text Find a string ‘man’ from a ‘A successful man’
1 Some Variations on Date Display 2 Print HTML Code What PHP prints will be placed into the file, and then the file is sent to the web client to be rendered.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Manipulation Masterclass By the VB Gods. In this masterclass, we will learn how to use some of the string manipulation function such as Len, Right, Left,
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
1 STRINGS String data type Basic operations on strings String functions String procedures.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Chapter 2 print / println String Literals Escape Characters Variables / data types.
Characters and Strings
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Chapter 2 1.What is the difference between print / println 2.What are String Literals 3.What are the Escape Characters for backslash, double quotataions,
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Lecture 4 Computer Programming // sample C++ program #include using namespace std; int main() { cout
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
ENGINEERING 1D04 Tutorial 2. What we’re doing today More on Strings String input Strings as lists String indexing Slice Concatenation and Repetition len()
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
28 Formatted Output.
C++ First Steps.
Definition of the Programming Language CPRL
String Methods Programming Guides.
Topics Designing a Program Input, Processing, and Output
Input and Output Upsorn Praphamontripong CS 1110
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Working with Strings Lecture 2 Hartmut Kaiser
Introduction to Programming
Representing Characters
Chapter 2 – Getting Started
Introduction to Programming
2.1 Parts of a C++ Program.
Manipulating Characters
Working with Strings Lecture 2 Hartmut Kaiser
Manipulating Text In today’s lesson we will look at:
The backslash is used to escape characters that are used in Python
Coding Concepts (Data- Types)
Introduction to Programming
Topics Designing a Program Input, Processing, and Output
CS190/295 Programming in Python for Life Sciences: Lecture 3
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Functions continued.
Topics Designing a Program Input, Processing, and Output
Introduction to Computer Science
Introduction to Programming
Output Manipulation.
Python Strings.
Exam Prep.
Chapter 1 c++ structure C++ Input / Output
Programming Techniques
Inputs, Outputs and Assignment
What We Want To Do User enters: Mary Smith
Presentation transcript:

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

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)

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

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

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

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

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