Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
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.
Java Programming Strings Chapter 7.
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 8 - Characters and Strings Outline 8.1Introduction.
Chapter 15 Strings String::Concat String::CompareTo, Equals, == If( string1 == S”Hello”) String1->Equals(S”Hello”) String1->CompareTo(S”Hello”) CompareTo.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
JavaScript, Third Edition
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Sanjay Goel, School of Business, University at Albany, SUNY 1 MSI 692: Special Topics in Information Technology Lecture 4: Strings & Arrays Sanjay Goel.
String Escape Sequences
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Strings Representation and Manipulation. Objects Objects : Code entities uniting data and behavior – Built from primitive data types.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Introduction to Java Java Translation Program Structure
Chapter 7: Characters, Strings, and the StringBuilder.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Characters and Strings
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
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.
EC-111 Algorithms & Computing Lecture #10 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
String and Lists Dr. José M. Reyes Álamo.
Computer Programming ||
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
JavaScript Objects.
String String Builder.
Chapter 8 - Characters and Strings
Primitive Types Vs. Reference Types, Strings, Enumerations
String Objects & its Methods
Chapter 7: Strings and Characters
MSIS 655 Advanced Business Applications Programming
Part a: Fundamentals & Class String
String and Lists Dr. José M. Reyes Álamo.
Representation and Manipulation
16 Strings.
JavaScript: Objects.
Introduction to Computer Science
String methods 26-Apr-19.
C++ Programming Lecture 20 Strings
Unit-2 Objects and Classes
Presentation transcript:

Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010

Bina Nusantara University 3 Outline Materi Introduction Fundamentals of Characters and Strings Strings

Bina Nusantara University 4 Introduction This chapter introduces the.NET Framework Class Library’s string- and character-processing capabilities and demonstrates how to use regular expressions to search for patterns in text.

Bina Nusantara University 5 Fundamentals of Characters and Strings Characters are the fundamental building blocks of C# source code. Every program is composed of characters that, when grouped together meaningfully, create a sequence that the compiler interprets as instructions describing how to accomplish a task. A string is a series of characters treated as a unit. These characters can be uppercase letters, lowercase letters, digits and various special characters: +, -, *, /, $ and others.

Bina Nusantara University 6 Fundamentals of Characters and Strings Example (sequences of charcaters in double quotation marks): “John Q. Doe” “9999 Main Street” “Waltham, Massachusetts” “(201) ” A declaration can assign a string literal to a string reference. string color = “blue”; Initialize string reference color to refer to the string literal object “blue”.

Bina Nusantara University 7 Strings Constructors Class string provides eight constructors for initializing strings in various ways.

Bina Nusantara University 8 String indexer, Length Property and CopyTo Method String indexer facilitates the retrieval of any character in the string. String property length returns the length of the string. String method CopyTo copies a specified number of characters from a string into a char array.

Bina Nusantara University 9

10 Comparing Strings

Bina Nusantara University 11 Extracting Substrings from strings Class string provides two Substring methods, which create a new string by copying part of an existing string. Each method returns a new string.

Bina Nusantara University 12 Finding a Substring within a String To find the first or last occurrence of a character within the string: Using a string variable type int index = where index is a variable that will store the zero-based position of the character within the string, str is the variable you want to search, is the string you are searching for. Type int to search for the last occurrence of a substring within the string.

13 Tips There are two ways of enumerating through all the characters in a string. One way is to write a loop where you maintain an index with an integer variable. The index begins at zero and increases until the index is equal to Length –1 (see "Finding the String's Length" earlier in this chapter) (Figure 4.41). The other way is to use a function called foreach.

Bina Nusantara University 14 Tips If you ask for an index greater than Length –1, the string class generates an exception. The exception (or error) is IndexOutOfBoundsException. You can access the characters of the string, but you can't modify them since strings are immutable

Bina Nusantara University 15 Tips If the IndexOf or LastIndexOf functions don't find any occurrences of the substring, the functions return –1. There are a few variations of the IndexOf and LastIndexOf functions. One variation lets you specify a location within the string where you want to start the search. This is useful for cases in which you wish to scan the string for one character, then when you find it, you want to get the next occurrence of the same character. In that case you specify that you want to begin the search in the position after the first occurrence.

Bina Nusantara University 16 Tips

Bina Nusantara University 17 References online.net/Manipulating_Strings_in_CSharp%E2%8 0%94Accessing_the_String%27s_Charactershttp://en.csharp- online.net/Manipulating_Strings_in_CSharp%E2%8 0%94Accessing_the_String%27s_Characters