String Methods Programming Guides.

Slides:



Advertisements
Similar presentations
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Advertisements

IS 1181 IS 118 Introduction to Development Tools Chapter 4 String Manipulation and Regular Expressions.
Regular Expression A regular expression is a template that either matches or doesn’t match a given string.
Regular Expressions in ColdFusion Applications Dave Fauth DOMAIN technologies Knowledge Engineering : Systems Integration : Web.
Chapter 06: Lecture Notes (CSIT 104) 1 Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 1 Copyright © 2008 Prentice-Hall. All rights reserved.
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
Introduction to Python
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
AOIT Introduction to Programming Unit 3, Lesson 10 Advanced Sequence Manipulation Copyright © 2009–2012 National Academy Foundation. All rights reserved.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Manipulating Text In today’s lesson we will look at: why we might want to pick out parts of text strings some BASIC functions that can be used to chop.
Copyright © 2008 Pearson Prentice Hall. All rights reserved Chapter 6 Data Tables and Amortization Tables Exploring Microsoft Office Excel 2007.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Chapter 2 print / println String Literals Escape Characters Variables / data types.
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
02/03/ Strings Left, Right and Trim. 202/03/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
13/06/ Strings Left, Right and Trim. 213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
Chapter Four Common facilities of procedural languages.
GCSE COMPUTER SCIENCE Practical Programming using Python
String and Lists Dr. José M. Reyes Álamo.
Logical Functions Excel Lesson 10.
Excel STDEV.S Function.
Topics Designing a Program Input, Processing, and Output
A Guide to SQL, Seventh Edition
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Variables, Expressions, and IO
Strings Part 1 Taken from notes by Dr. Neil Moore
Microsoft Visual Basic 2005 BASICS
String Manipulation.
Decision Structures, String Comparison, Nested Structures
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
String Manipulation Part 2
Decision Structures, String Comparison, Nested Structures
Creation, Traversal, Insertion and Removal
Manipulating Text In today’s lesson we will look at:
Microsoft Visual Basic 2005 BASICS
String and Lists Dr. José M. Reyes Álamo.
Coding Concepts (Data- Types)
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Basic String Operations
Python Programming Language
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
The Data Element.
Topics Basic String Operations String Slicing
Topics Designing a Program Input, Processing, and Output
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Introduction to Computer Science
Lecture 5 SQL FUNCTIONS.
Python Strings.
Topics Basic String Operations String Slicing
The Data Element.
Understanding Variables
Variables in C Topics Naming Variables Declaring Variables
ASCII LP1.
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Topics Basic String Operations String Slicing
Primitive Data Types and Operators
Presentation transcript:

String Methods Programming Guides

String Methods (String Manipulation) String manipulation is very useful and very widely used in every language. Often, programmers are required to break down strings and examine them closely. For example, a password strength checker would have to strip a string down and examine them closely to see if it contains letters, numbers and/or symbols.

String Methods (String Manipulation) This presentation will take a look at the various methods of manipulating strings, covering things from basic methods to regular expressions in Python. String manipulation is a skill that every Python programmer should be familiar with.

String Methods (String Manipulation) The most basic way to manipulate strings is through the methods that are built into Python. We can perform a number of tasks on strings through these methods.

String Methods (String Manipulation) We can perform: String Checks: - Find the length of a string - Find out if a string is all in uppercase - find out if a string is all in lowercase - find out if a string’s words all start with capitals letters - Check whether a string is alphanumeric(contains both letters and numbers) - Check whether a string contains only numbers - Check whether a string contains only letters - Check whether a string only contains spaces - Find the location of a character in a string - Count how many times a character appears in a string String to Lists Conversions: - Split a string into a number of items on a list String Formatting Methods: - Turn a string upper case - Turn a string lower case - Capitalize a string (make first letter capital) - Capitalize each word in a string - Swap the case of each letter in a string around - Add spaces in either side of a string. Other Useful String Methods: - Return the character at a certain position of a string - Replace letters and words in a string

Concatenation This simply means ‘joining’. We know from before that the ‘+’ operator is used to add numeric data types together. This operator has a different function when it deals with strings. The ‘+’ sign simply joins together two or more string. Example: full_name_no_space = firstname + surname Full_name = firstname + “ ” + surname

Find the length of a string The len function: This helps us find the length of a string (how many characters it has – including spaces) Or

Character of string at position… from left string[3] from right string[-3]

Look at each character of string in turn

Find out if a string is all in uppercase

Find out if a string is all in lowercase

Check whether a string is alphanumeric (contains only letters and numbers)

Check whether a string contains only letters

Check whether a string contains only number

Find out if a string’s words all start with capitals letters

Check whether a string only contains spaces

Other useful string manipulation functions

String Formatting Methods

Turn a string upper case Or

Turn a string lower case Or

Capitalise a string (make first letter capital) Or

Capitalize each word in a string

Swap the case of each letter in a string around Or

Add spaces to indent or centre strings on screen.

Pretty Printing string.format() method Here is an example of how the variables (contained in the format function’s brackets) is printed according to some pretty printing rules. For digits: {0:2d} {1:3d} {2:4d} means, in the first column (0) allow for 2 digits, in the second column (1) allow for 3 digits etc. For strings: {0:10} means, in the first column, allow for 10 characters.

Converting between Strings and Lists

Split a string into a number of items on a list

Split a string into 2 items on a list around a specific letter

Displaying only parts of a String

Return the first few letters/numbers/characters of the string from the left

Return the last few letters/numbers/characters of the string from the right

Return a certain number of letters/numbers/characters within the string

Other Useful Methods

Replace letters and words in a string

Count how many times a character appears in a string Or

Find the location of a character in a string Or