Strings IDIA 618 Spring 2013 Bridget M. Blodgett.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
COMP234 Perl Printing Special Quotes File Handling.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
23-Jun-15 Strings, Etc. Part I: String s. 2 About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects,
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
28-Jun-15 String and StringBuilder Part I: String.
IS 1181 IS 118 Introduction to Development Tools Chapter 4 String Manipulation and Regular Expressions.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
PHP : Hypertext Preprocessor
Strings and Arrays. String Is a sequence of characters. Example: “hello”, “how are you?”, “123”,and are all valid string values.
Practical PHP IDIA Spring 2012 Bridget M. Blodgett.
Tutorial 14 Working with Forms and Regular Expressions.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
PHP Workshop ‹#› Data Manipulation & Regex. PHP Workshop ‹#› What..? Often in PHP we have to get data from files, or maybe through forms from a user.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Fall Week 4 CSCI-141 Scott C. Johnson.  Computers can process text as well as numbers ◦ Example: a news agency might want to find all the articles.
Strings CS303E: Elements of Computers and Programming.
Strings in PHP Working with Text in PHP Strings and String Functions Mario Peshev Technical Trainer Software University
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Web Database Programming Week 3 PHP (2). Functions Group related statements together to serve “a” specific purpose –Avoid duplicated code –Easy maintenance.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
PHP’s Regular Expression Functions (Perl Compatible) Examples taken from: Beginning PHP 5 and MySQL 5 From Novice to Professional.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Copyright © Curt Hill Regular Expressions Providing a Search Pattern.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
17-Feb-16 String and StringBuilder Part I: String.
DCT1063 Programming 2 CHAPTER 3 STRINGS Mohd Nazri Bin Ibrahim Faculty of Computer, Media & Technology TATi University College
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
13/06/ Strings Left, Right and Trim. 213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
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.
Arrays and Strings. Arrays in PHP Arrays are made up of multiple memory blocks, each with the same name and differentiated by an index number Each block.
Computer Programming ||
String Processing Upsorn Praphamontripong CS 1110
Engineering Innovation Center
SAS in Data Cleaning.
Creation, Traversal, Insertion and Removal
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
String Manipulation and More Controls
String functions
Data Manipulation & Regex
Microsoft Visual Basic 2005: Reloaded Second Edition
Introduction to Computer Science
String methods 26-Apr-19.
Python Strings.
String functions
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
What We Want To Do User enters: Mary Smith
Presentation transcript:

Strings IDIA 618 Spring 2013 Bridget M. Blodgett

Strings on the Web The bulk of web data is manipulated or used in some type of string form In order to handle this PHP has significant functionality built in to deal with strings – Nearly 100 that focus exclusively on strings Some popular functions include: – Searching for text, replacing pieces of text, (re)formatting text, encoding/decoding, and regular expressions

Quotes Always check to make sure you are using the appropriate types of quotation marks (‘’ or “”) – ‘’ will reproduce the string exactly as it is typed – “” will try to interpret the string and use additional features where appropriate: Any variable names in the string will be replaced with that variables value Special characters can be included through the use of an escape

Implementing Variables If you are trying to substitute the contents of a variable in a string it can be a bit complicated – For example: $favoriteAnimal = “cat”; echo “My favorite animals are $favoriteAnimals”; There are a couple different ways to solve this problem 1) using {} to offset the variable or 2) interweave “” and php using the concatenator

HEREDOC & NOWDOC $myString = < < < DELIMITER (insert string here) DELIMITER; $myString = < < < ’DELIMITER’ (insert string here) DELIMITER;

String Functions To find a string’s length: strlen($var) – Useful to: loop through all the characters in a string or validate a string to make sure it ’ s the correct length Strings are indexed similar to arrays – So you can use $var[0] to add or determine the placement of a character in a string Substr($var, start, end) – Negative numbers count backwards from the end – Substr_replace($var) lets you actually replace characters

Searching Strings strstr($var, “str”, true) – is the text in the string? The true shows the text to the start of found text strpos($var, “str”) / strrpos($var, “str”) – index position of first and last occurrence of the text substr_count($var, “str”) – how many times does it occur? strbrk ($var, “str”, startat) – find any of a list of characters and displays the rest of the string from the first found

Replacing Text str_replace(“str1”, “str2”, $var, $num) substr_replace($var, “str”, position, num to replace) – replaces the remainder of the text with the string and provides a new copy of the string (or up to the num you specify) – Negative numbers replace from the end of the string and a 0 simply inserts the new text strtr($var, what to replace, replacement) – Great for cleaning inputs (replacing “ “ with %20)

Changing Case strtolower() ucfirst() lcfirst() ucwords() To make searching case insensistive: – stristr(), stripos(), strripos(), str_ireplace()

Trimming Strings trim() removes white space from the beginning and end of a string ltrim() removes white space only from the beginning of a string rtrim() removes white space only from the end of a string You can also specify characters to treat as whitespace

$milton1 = “1: The mind is its own place, and in it self\n”; $milton2 = “2: Can make a Heav’n of Hell, a Hell of Heav’n.\n”; $milton3 = “3: What matter where, if I be still the same,\n”; echo “ ”; echo ltrim( $milton1, “0..9: “ ); echo ltrim( $milton2, “0..9: “ ); echo ltrim( $milton3, “0..9: “ ); echo “ ”;

Shaping Strings str_pad($var, padding, character, STR_PAD_LEFT/RIGHT/BOTH) – adding padding to the string wordwrap($var, linelength, char to use) – By default uses the \n but can be set to use things like Number_format($var, # decimal places, replace decimal, replace commas)

Exercise Using these string functions create a box similar to the one we made last week using a loop Change the text in your strings so the outline of the box is different than the inside of the box