Chapter 6 Introduction to Arrays And String

Slides:



Advertisements
Similar presentations
5.
Advertisements

By Nguyen Minh Quy - UTEHY
Chapter : STRING. Slide 2 9:06:37 AM 1. Introduction String and character processing capabilities –Text editors –Word processors… Expand from previous.
3.3 Static analysis by tools. Contents The objective of static analysisCompare static and dynamic testingBenefits of using static analysis Recall typical.
Arrays An array is a list or series of values all referenced by the same name Also referred to as a table An element is an individual item in the array.
Cách trộn thư trong Office 2003 Ứng dụng để làm giấy khen, giấy mời.
Chào mừng quý thầy cô và các em TRƯỜNG THPT TRẦN VĂN KỶ TỔ LÝ – TIN - KTCN.
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
Trường THPT Long Châu Sa
Javascript Giáo viên: TS. Trương Diệu Linh Bộ môn Truyền thông & Mạng
Truy vấn nâng cao HIENLTH - Database.
Các kiểu dữ liệu trong VB
Giáo viên: Nguyễn Ngọc Thúy Hằng Đơn vị: Trường THPT Lê Quý Đôn
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
ĐỘT BIẾN GEN MÃ HÓA CHUỖI α-GLOBIN
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.
TỔNG QUAN VỀ NGÔN NGỮ LẬP TRÌNH C/C++
Quản trị dự án TS. Trịnh Thùy Anh.
1. Quyền Admistrator, quyền Standard hoặc Limited 2. Kiểm tra kết nối mạng nội bộ, Internet 3. Một số nội dung của Quy nội bộ số 72/QyĐ-KTNB 4. L ư u ý.
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
Internet & E-Commerce
Ngôn ngữ lập trình C/C++
Ngôn ngữ lập trình C/C++
CHƯƠNG II CÁC HÀM NHẬP XUẤT
GIÁO TRÌNH ĐÀO TẠO TRƯỜNG ĐẠI HỌC SÀI GÒN
SỬ DỤNG EXCEL ĐỂ TRÍCH KHẤU HAO TSCĐ
Ngôn ngữ lập trình C/C++
Bảo mật - Mã hóa dữ liệu Nội dung trình bày :
Hướng dẫn viết đề cương nghiên cứu
LẬP TRÌNH HƯỚNG ĐỐI TƯỢNG C++
Chương 8 KẾT NỐI VỚI SQL SERVER & ỨNG DỤNG TRÊN C#
Vấn đề ngôn ngữ lập trình
Mảng Lập trình nâng cao.
Phần 1: Ngôn ngữ lập trình 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
Ra quyết định kinh doanh
Con trỏ Bài 8.
Cấu hình đơn giản cho Router
Sự truyền ánh sáng trong tinh thể dị hướng
Ring ? Bus ? ? Mesh ? Start ?. Ring ? Bus ? ? Mesh ? Start ?
Môn: Lập trình Hướng đối tượng (Object Oriented Programming)
TÀI LIỆU GIẢNG DẠY IC3 GS4 SPARK
GIÁO TRÌNH ĐÀO TẠO TRƯỜNG ĐẠI HỌC SÀI GÒN
Bài 8 (6 tiết): CÂY (TREE) A. CÂY VÀ CÂY NHỊ PHÂN (2 tiết)
Chapter : Arrays.
ỨNG DỤNG HIV INFO 3.0 QUẢN LÝ SỐ LIỆU NGƯỜI NHIỄM HIV/AIDS
GVHD: TS Lê Vũ Tuấn Hùng HV: Trịnh Thị Quỳnh Như
File Transfer Protocol (FTP) là cơ chế truyền tin dưới dạng tập tin (file). Thông qua giao thức TCP/IP FTP là dịch vụ đặc biệt vì nó dùng tới 2 port Port.
KỸ THUẬT LẬP TRÌNH GV: Phạm Thị Xuân Diệu
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
Chương 4 - CÁC MÔ ĐUN ĐiỀU KHIỂN TRONG HỆ THỐNG CƠ ĐiỆN TỬ
Data Integrity TÍNH TOÀN VẸN DỮ LiỆU.
Chương 4: FORMS Microsoft Access.
1. Đổi chỗ trực tiếp – Interchange Sort
Chương 5: Relational mapping
Buổi 8 Khái niệm về Binding
Please click through slides at your leisure
Chương 3. Lập trình trong SQL Server TRIGGER
2D Transformations Các phép biến đổi 2D
Company LOGO CĂN BẢN VỀ MẠNG NGUYEN TAN THANH Xem lại bài học tại
Programming In Visual Basic .NET
Presentation transcript:

Chapter 6 Introduction to Arrays And String

Arrays? Khi nào dùng Array List or series of values all referenced by the same name and type Similar to list of values for list boxes and combo boxes - without the box Use an array to keep a series of variable for later processing such as Reordering Calculating Printing 2011

Array Terms Element Index (or subscript) Boundaries Individual item in the array Index (or subscript) Zero based number used to reference the specific elements in the array Must be an integer Boundaries Lower Subscript, 0 by default Upper Subscript 2011

Simple Array Example (p353) strName Array [0] [1] (2) (3) (4) (5) (6) (7) (8) (9) Janet Baker George Lee Sue Li Samuel Hoosier Sandra Weeks William Macy Andy Harrison Ken Ford Denny Franks Shawn James 2011

Declaring and Creating Arrays p355 Cách 1 int[] c = new int[ 12 ]; Cách 2 int[] c; // declare the array variable c = new int[ 12 ]; // create the array; assign to array variable Cách 2 tương đương cách 1. string[] b = new string[ 100 ]; // create string array b string[] x = new string[ 27 ]; // create string array x 2011

Using an Array Initializer Optionally, the elements in the array may be assigned values in the statement int[] n = { 10, 20, 30, 40, 50 }; Index Value 10 1 20 2 30 3 40 4 50 2011

Using an Array Initializer Index Value Ace 1 Deuce 2 Three 3 Four 4 Five 5 Six string[] faces = { "Ace", "Deuce", "Three", "Four", "Five", "Six"}; 2011

Nhâp xuất Array Nhập, xuất thực chất là gán hoặc lấy giá trị của array tại vị trí nào đó. Thông thường nhập xuất mảng kết hợp vòng lặp. Ví dụ nhập mảng: int [] A= new int [50]; Random n = new Random(); int i=0; while (i < A.Length) { A[i] = n.Next(1, 91);// nhập cho item thứ i i++; } 2011

Nhâp xuất Array long t = 0; while (i < A.Length) { t =t+ A[i]; i++; Ví dụ truy xuất Array: long t = 0; while (i < A.Length) { t =t+ A[i]; i++; } 2011

Nhâp xuất Array Truy xuất các phần tử trong array dùng cấu trúc lặp for each rất hiệu quả. Syn tax foreach ( type identifier in arrayName ) statement 2011

Nhâp xuất Array Truy xuất qua vị trí Truy xuất qua foreach long tongmang(int[] A) { int i = 0, x; long t = 0; while (i < A.Length) x = A[i]; t += x; i++; } return t; long tongmangForeach(int[] A) foreach (int x in A) 2011

Multidimensional Arrays Multidimensional arrays with two dimensions are often used to represent tables of values consisting of information arranged in rows and columns 2011

Rectangular Arrays 2011

declared and initialized <Kiểu dữ liệu> [ , ] <Tên mảng> <Tên mảng> = new <Kiểu dử liệu> [<số dòng> ,<số cột> ] Khởi gán mảng hai chiều chữ nhật: int[ , ] b = { { 7, 2 }, { 5, 8 } } b[1,0]=? 7 2 5 8 2011

Truy xuất phần tử của mảng hai chiều chữ nhật < Tên mảng > [ i , j ] trong đó I là chỉ số dòng, j là chỉ số cột Ví dụ : X=A[4,5]; static void PrintArray(int[,] a) { Console.WriteLine(); for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < a.GetLength(1); j++) Console.Write(" {0}", a[i,j]); } 2011

Truy xuất phần tử của mảng hai chiều chữ nhật < Tên mảng > [ i , j ] trong đó I là chỉ số dòng, j là chỉ số cột Ví dụ : X=A[4,5]; int TongMang(int[,] a)//tong mang 2 chieu { long T=0; for (int i = 0; i < a.GetLength(0); i++) for(int j = 0; j < a.GetLength(1); j++) T=T+a[i,j]; return T; } 2011

Mảng Jagged (Mảng lởm chởm) Mảng Jagged là mảng mà mỗi phần tử là một mảng khác. Và hiển nhiên trong mảng jagged số cột trong các dòng sẽ không bằng nhau. 2011

Khai Báo Và Khởi Tạo Mảng Jagged Khai báo mảng Jagged: < Kiểu dũ liệu > [ ] [ ] < Tên mảng > - Khởi tạo mảng jagged: < Tên mảng > = new <Kiểu dữ liệu> [số dòng của mảng ] [ ]; Trong quá trình nhập giá trị số dòng cho mảng chúng ta sẽ nhập số cột tương ứng cho mỗi dòng. int[][] jagged = { new int[] { 1, 2 }, new int[] { 3 }, new int[] { 4, 5, 6 } }; int[][] c; c = new int[ 2 ][ ]; // create 2 rows c[ 0 ] = new int[ 5 ]; // create 5 columns for row 0 c[ 1 ] = new int[ 3 ]; // create 3 columns for row 1 2011

String String s = "nguyen van thang"; s = System.Threading.Thread.CurrentThread .CurrentCulture.TextInfo.ToTitleCase(s.ToLower());//doi thanh proper 2011

Fundamental 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 2011

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"; 2011

String Methods Length property CopyTo Returns the length of the string Copies specified number of characters into a char array CopyTo ( int sourceIndex, array[] destination, int destinationIndex, int count ) 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; © 10/18/2011.

String Methods String comparison Method Equals Greater than (1) Less than (-1) Equal (0) Method Equals Test objects for equality Return a Boolean Uses lexicographical comparison © 10/18/2011.

String Methods IndexOf(char value) IndexOf(char value, int StartIndex) IndexOf methods: Reports the index of the first occurrence of a String, or one or more characters, within this string. IndexOf(char value) IndexOf(char value, int StartIndex) IndexOf(string value) IndexOf(string value, int StartIndex) © 10/18/2011.

String Methods Bool MyString.StartsWith( s ) Bool MyString.EndsWith( s ) string MyString.Substring ( int startIndex, int length ) MyString.ToLower( ) MyString.ToUpper( ) MyString.ToString( ) MyString.Trim( ) MyString.TrimEnd( ) MyString.TrimStart ( ) © 10/18/2011.

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) © 10/18/2011.