Chapter : STRING. Slide 2 9:06:37 AM 1. Introduction String and character processing capabilities –Text editors –Word processors… Expand from previous.

Slides:



Advertisements
Similar presentations
 2002 Prentice Hall. All rights reserved. 1 Chapter 15 – Strings, Characters and Regular Expressions Outline 15.1Introduction 15.2 Fundamentals of Characters.
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Strings in Java 1. strings in java are handled by two classes String &
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
CHÀO QUÝ THẦY CÔ VÀ CÁC EM ĐẾN THAM DỰ TiẾT HỌC HÔM NAY Bài dạy: PPCT: 63.
5.
String class  Construct a string  String str = new String(“welcome”);  Char[] charr = {‘G’, ‘o’, ‘o’, ‘d’};  String mes = new String(charr);  A full.
Chapter 15 Strings String::Concat String::CompareTo, Equals, == If( string1 == S”Hello”) String1->Equals(S”Hello”) String1->CompareTo(S”Hello”) CompareTo.
 2006 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
Các phương pháp hàn nóng chảy Môn hàn Tàu Thủy Th.s Trần Ngọc Dân
COMPANY LOGO Network+ Guide, 4e Receive gifts !. COMPANY LOGO Network+ Guide, 4e Objectives  Understanding structure of IP addresses, methods of network.
Cài đặt Moodle Cài đặt Moodle trên môi trường Windows Cục CNTT-Bộ GD&ĐT.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
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.
Strings Mr. Smith AP Computer Science A. What are Strings? Name some of the characteristics of strings: A string is a sequence of characters, such as.
1 Java Strings Dr. Randy M. Kaplan. 2 Strings – 1 Characters are a fundamental data type in Java It is common to assemble characters into units called.
CSI 3125, Preliminaries, page 1 String. CSI 3125, Preliminaries, page 2 String Class Java provides the String class to create and manipulate strings.
Chapter 3A Strings. Using Predefined Classes & Methods in a Program To use a method you must know: 1.Name of class containing method (Math) 2.Name of.
Java String 1. String String is basically an object that represents sequence of char values. An array of characters works same as java string. For example:
Cách trộn thư trong Office 2003 Ứng dụng để làm giấy khen, giấy mời.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
BÀI 3. ĐƯỜNG THẲNG VÀ MẶT PHẲNG SONG SONG SỞ GD&ĐT ĐIỆN BIÊN TRƯỜNG THCS-THPT TẢ SÌN THÀNG BÀI DỰ THI SOẠN GIẢNG E-LEARNING Chương II ĐƯỜNG THẲNG VÀ MẶT.
Rèn luyện nghiệp vụ sư phạm 3
KIỂM TRA BÀI CŨ 1) Thế nào là đơn thức ? Cho ví dụ về đơn có biến là x, y, có bậc là 3. 2.a) Thế nào là bậc của đơn thức có hệ số khác 0 ? Muốn nhân hai.
Truy vấn nâng cao HIENLTH - Database.
Chúa Nhật 18 Thường Niên Năm C
Giáo viên: Nguyễn Ngọc Thúy Hằng Đơn vị: Trường THPT Lê Quý Đôn
The Methods and What You Need to Know for the AP Exam
Java I/O.
CHƯƠNG 5. CẤU TẠO ĐƯỜNG KIẾN TẠO. Nội dung chính KHÁI NIỆM CHUNG CÁC DẠNG CẤU TẠO ĐƯỜNG KIẾN TẠO CÁCH ĐO ĐẠC VÀ THU THẬP CÁC SỐ LIỆU CẤU TẠO ĐƯỜNG.
LOGO QUẢN LÝ LƯU LƯỢNG VÀ ĐIỀU KHIỂN TẮC NGHẼN 1 Giảng viên hướng dẫn: TS Lê Trung Quân Nhóm thực hiện: Trần Thị Mỹ Thú - CH
C# - Strings.
Strings, StringBuilder, and Character
Strings, Characters and Regular Expressions
String String Builder.
1 BÀI 6 BẤM CÁP VÀ CHIA SẺ DỮ LIỆU MẠNG. 2 Nội Dung  Bấm cáp xoắn đôi đúng chuẩn Phương pháp bấm cáp chuẩn A Phương pháp bấm cáp chuẩn B  Kết nối máy.
Primitive Types Vs. Reference Types, Strings, Enumerations
Top 10 đáng tin cậy cá cược bóng đá online trang web ở Việt Nam.
Kính Chào Cô và Các b ạ n thân m ế n !!!!!. HÌNH THỨC CHÍNH THỂ CỦA NHÀ NƯỚC CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM VÀ MỘT SỐ NƯỚC TRÊN THẾ GIỚI. Thuyết trình.
Các hệ mã truyền thống Cryptography Криптография Trần Nguyên Ngọc
CHƯƠNG II CÁC HÀM NHẬP XUẤT
SỬ DỤNG EXCEL ĐỂ TRÍCH KHẤU HAO TSCĐ
Bảo mật - Mã hóa dữ liệu Nội dung trình bày :
LẬP TRÌNH HƯỚNG ĐỐI TƯỢNG C++
Kỹ Năng Ghi Nhận - Affirmation
IP ADDRESS Subnet MasK & Receive gifts !.
Chương 8 KẾT NỐI VỚI SQL SERVER & ỨNG DỤNG TRÊN C#
TRƯỜNG ĐẠI HỌC KHOA HỌC TỰ NHIÊN KHOA VẬT LÝ
Hệ quản trị Cơ sở dữ liệu Giới thiệu
Download Nhạc Trong Internet
Chapter 7: Strings and Characters
Object Oriented Programming
Dược Thảo Lợi Hại Ra Sao Kính thưa quí bạn, slide show nầy nói về những điều cần lưu ý khi tìm đọc các thông tin về các loại thuốc phụ trợ hoặc bổ sung,
Sự tự tụ tiêu Phạm Văn Tiến Lê Minh Tiến Từ Khánh Long
Con trỏ Bài 8.
Môn: Lập trình Hướng đối tượng (Object Oriented Programming)
Chapter 05 BẢO MẬT TRONG HỆ THỐNG WLAN
CẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬT
Mảng Bài 7.
BÀI 29: LỌC DỮ LIỆU TỪ DANH SÁCH DỮ LIỆU
Chapter 6 Introduction to Arrays And String
KHOA CÔNG NGHỆ ĐIỆN TỬ VÀ TRUYỀN THÔNG Bộ môn Công nghệ Truyền thông
Please click through slides at your leisure
Twelfth Sunday in Ordinary Time Year C
SỞ GIÁO DỤC VÀ ĐÀO TẠO ĐIỆN BIÊN TRƯỜNG THPT MÙN CHUNG
Company LOGO CĂN BẢN VỀ MẠNG NGUYEN TAN THANH Xem lại bài học tại
Visual Programming COMP-315
Presentation transcript:

Chapter : STRING

Slide 2 9:06:37 AM 1. Introduction String and character processing capabilities –Text editors –Word processors… Expand from previous chapters –Class String and type char –Class StringBuilder

Slide 3 9:06:37 AM Fundamentals of Characters and Strings Importance of characters –Character constants Character code Unicode character set –String Object of class String in System namespace Consist of characters

Slide 4 9:06:37 AM String Constructors Class String –Provides eight constructors for initialing strings string file = "C:\\MyFolder\\MySubFolder\\MyFile.txt"; string file

Slide 5 9:06:37 AM Introduction String and character processing capabilities –Text editors –Word processors… Expand from previous chapters –Class String and type Char (System namespace) –Class StringBuilder (System.Text namespace)

Slide 6 9:06:37 AM Fundamentals of Characters and Strings Importance of characters –Character constants Character code (ex. 122  ‘z’, 10  ’\n’) Unicode character set (see Appendix G, Unicode) –String Consist of characters Object of class String in System namespace using String to refer to the class String and string to refer to an object of class String

Slide 7 9:06:37 AM String class: Initialing strings Using constructors of String class: new String (char[ ] chuoi_ki_tu); new String (char[ ] chuoi_ki_tu, int vi_tri_bat_dau_lay, int so_ki_tu); new String (char ki_tu, int so_lan_lap);

string output; string originalString, string1, string2, string3, string4; char[] characterArray = { 'b', 'i', 'r', 't', 'h', ' ', 'd', 'a', 'y' }; // string initialization originalString = "Welcome to C# programming!"; string1 = originalString; string2 = new string( characterArray ); string3 = new string( characterArray, 6, 3 ); string4 = new string( 'C', 5 ); output = "string1 = " + "\"" + string1 + "\"\n" + "string2 = " + "\"" + string2 + "\"\n" + "string3 = " + "\"" + string3 + "\"\n" + "string4 = " + "\"" + string4 + "\"\n";

StringCons tructor.cs

Slide 10 9:06:37 AM String Length Property and CopyTo Method Length property –Returns the length of the string CopyTo –Copies specified number of characters into a char array CopyTo ( int sourceIndex, array[] destination, int destinationIndex, int count )int Copy To: tại 1 ví trí trên chuỗi gốc ( sourceIndex, ), lấy một số ký tự ( count), Copy tới một vị trí ( destinationIndex), trên một bảng dãy ký tự Unicode destination;

StringMethods string string1, output; char[ ] characterArray; string1 = "hello there"; characterArray = new char[ 10 ]; string1.CopyTo( 0, characterArray, 2, 5 ); output += "\nThe character array is: "; for ( int i = 0 ; i < characterArray.Length; i++ ) output += characterArray[ i ]; hello

Slide 12 9:06:37 AM Comparing Strings String comparison –Greater than (1) –Less than (-1) –Equal (0) Method Equals –Test objects for equality –Return a Boolean –Uses lexicographical comparison

Slide 13 9:06:37 AM Comparing Strings Method Equals: test objects for equality –Return a bool value: true if equal bool String.Equals (String s1, String s2) bool objectString.Equals (String s) Method CompareTo: greater than, less than –Return a int value: int String.Compare (String s1, String s2) int String.Compare (String s1, String s2, bool ignoreCase) int objectString.CompareTo (String s)

Slide 14 9:06:37 AM Comparing Strings String s1, s2; S1= ; S2= ; S1.CompareTo(s2) hello hi Return 1: S1 > S2 car Car Return -1: S1 < S2 Cat Car Return -1: S1 < S2

Slide 15 9:06:37 AM Locating Characters in Strings IndexOf methods: Reports the index of the first occurrence of a String, or one or more characters, within this string.String –IndexOf(char value) –IndexOf(char value, int StartIndex) –IndexOf(string value) –IndexOf(string value, int StartIndex) –;–;

Slide 16 9:06:37 AM Locating Characters in Strings IndexOfAny method: report the first occurrence int objectString.IndexOfAny (char[] value) int objectString.IndexOfAny (char[] value, int startIndex)

Slide 17 9:06:37 AM Locating Characters in Strings –LastIndexOf method: report the last occurence int objectString.LastIndexOf (string value) int objectString.LastIndexOf (string value, int startIndex) int objectString.LastIndexOf (string value, int startIndex, int limit) int objectString.LastIndexOf (char value) int objectString.LastIndexOf (char value, int startIndex) –LastIndexOfAny method: report the last occurrence int objectString.LastIndexOf (char[] value) int objectString.LastIndexOf (char[] value, int startIndex)

Slide 18 9:06:37 AM Working With String 1.Bool MyString.StartsWith( s ) 2.Bool MyString.EndsWith( s ) 3.string MyString.Substring ( int startIndex, int length )stringint 4.MyString.ToLower( ) 5.MyString.ToUpper( ) 6.MyString.ToString( ) 7.MyString.Trim( ) 8.MyString.TrimEnd( ) 9.MyString.TrimStart ( )

Slide 19 9:06:37 AM StartsWith(strA) strA=“Working with String” strB=“w” strA.StartsWith("T") = F strA.StartsWith(strB) = F strA.StartsWith(strB.ToUpper) = T

Slide 20 9:06:37 AM Example strA=“Working with String” strB = "w“ strA.IndexOf("w")= 8 strA.IndexOf(strB.ToUpper) = 0 strA.IndexOf(strB.ToUpper, 3) = -1 strA.IndexOf(“ “, 3) = 7

Slide 21 9:06:37 AM Example strA=“Working with String” strB = "w“ strA.Substring(8)= with String strA.Substring(8, 4)= with strA.Substring(strA.IndexOf("S")) = String

Slide 22 9:06:37 AM Replace String Methods Method Replace (phương thức thay thế chuỗi) –Original string remain unchanged –String objectString.Replace (String oldValue, String newValue) –String objectString.Replace (char oldValue, char newValue)

Slide 23 9:06:37 AM Tách chuỗi Sử dụng phương thức Split() của lớp String: phân tích một chuỗi ra thành các chuỗi con dựa vào ký tự phân cách. Cú pháp: Split (char[] sign), hàm trả về một mảng chuỗi Để sử dụng Split(), chúng ta truyền vào một mảng các ký tự phân cách, các ký tự này được dùng để chia các từ trong chuỗi. Ví dụ: Tách chuỗi “Nguyễn Văn An” dựa vào khoảng trắng.

Slide 24 9:06:37 AM Ví dụ string s1 = “Nguyễn Văn An"; char[ ] space = {' '}; string[ ] s; s = s1.Split (space);//tham so truyen la mang ky tu txtHo.Text = s[0]; txtTen.Text = s[s.Length - 1]; for ( int i=1; i<s.Length-2; i++) { txtHolot.Text += s[i] + “ “; } Nguyễn Văn An

Slide 25 9:06:37 AM Finish