Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?

Slides:



Advertisements
Similar presentations
Strings Testing for equality with strings.
Advertisements

Introduction to Computers and Programming Lecture 7:
Decisions in Python Comparing Strings – ASCII History.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Dale & Lewis Chapter 3 Data Representation
Python Control of Flow.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
Lists and More About Strings CS303E: Elements of Computers and Programming.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
String Class in Java java.lang Class String java.lang.Object java.lang.String java.lang.Object We do not have to import the String class since it comes.
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.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
1 Data Comparisons and Switch Data Comparisons Switch Reading for this class: L&L 5.3,
Palindromes revisited Here's a simpler program for checking palindromes: int nums[100]; int i = 0, a; cin >> a; while(a > 0) { nums[i++] = a; cin >> a;
Required Functions for Program 3 int readUntilValidBaseRead( ); int readNumbersReturningValue( int base ); int decimalValueOf( char chDigit ); bool isValid(
Copyright © 2009 Lumina Decision Systems, Inc. Regular Expressions in Analytica 4.2 Lonnie Chrisman Lumina Decision Systems Analytica User Group 9 July.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
Regular Expressions What is this line all about? while (!($search =~ /^\s*$/)) { It’s a string search just like before, but with a huge twist – regular.
GREP. Whats Grep? Grep is a popular unix program that supports a special programming language for doing regular expressions The grammar in use for software.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
Characters and Strings. Characters  New primitive char  char letter; letter = ‘a’; char letter2 = ‘C’;  Because computers can only represent numbers,
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Perl Day 4. Fuzzy Matches We know about eq and ne, but they only match things exactly We know about eq and ne, but they only match things exactly –Sometimes.
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
Decision Structures, String Comparison, Nested Structures
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
Strings The Basics. Strings a collection data type can refer to a string variable as one variable or as many different components (characters) string.
Advanced Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
An Introduction to Regular Expressions Specifying a Pattern that a String must meet.
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
Strings Characters and Sentences 1.Overview 2.Creating Strings 3.Slicing Strings 4.Searching for substrings 1.
Dr. Sajib Datta Feb 21,  In the last class we discussed: ◦ Bubble sort  How it works  performance.
CPT: Chars/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to look at how C processes characters 4. Character.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Selection Part 2 Using Logical Operators, how strings are compared and random numbers.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
CONTROL 3 DAY /29/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
CompSci 101 Introduction to Computer Science April 7, 2015 Prof. Rodger.
Concatenation + Tack new stuff onto the end/right-hand side of a string “New stuff” can be: Char variable String variable Char literal String literal.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Discussion 4 eecs 183 Hannah Westra.
© A+ Computer Science - Magpie Chatbot Lab © A+ Computer Science -
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
A basic tutorial for fundamental concepts
String Manipulation.
Decision Structures, String Comparison, Nested Structures
Five-minute starter task
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Decision Structures, String Comparison, Nested Structures
String Encodings and Penny Math
Passing Parameters by value
Comparing Strings – How to
Coding Concepts (Data- Types)
functions: argument, return value
CISC101 Reminders All assignments are now posted.
Character Arrays char string1[] = “first”;
String Encodings and Penny Math
REGEX.
Variables and Constants
An Intro to Regex in R Alan Wu.
COMPUTING.
Presentation transcript:

Examples of comparing strings

“ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”? No – has to match every character “ABC” < “abc”? Yes – upper case is less than lower case “Bob” ‘R’

More “123 Main” > “99 South” ? Yes, “1” < “9” “ABC” > “ ABC”? No! “ “ comes before anything else! “ABC” “1” “12” < “14”? Yes – “2” < “4” “99” “1” “App” < “Apple”? Yes – the same until the shorter one runs out, shorter one is less

Upper and Lower case How to test a character to see if upper case? In Python, char.isupper() returns True if upper In Python, “A” <= char <= “Z” works too In any language, char >= “A” and char <= “Z” Do NOT use ASCII codes where the characters themselves will do! NO! 65 <= ord(char) <= 91 NO! ord(char) == 32 (same as char == “ “)