CIS16 Application Development and Programming using Visual Basic.net

Slides:



Advertisements
Similar presentations
Chapter 11: Classes and Objects
Advertisements

Chapter 9: Sequential Access Files and Printing
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
Chapter 8: Manipulating Strings
Chapter 7: Working with Arrays
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Fundamentals of Python: First Programs
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 8: Manipulating Strings
Tutorial 9: Sequential Access Files and Printing1 Tutorial 9 Sequential Access Files and Printing.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Chapter 5: More on the Selection Structure
Chapter 7: Characters, Strings, and the StringBuilder.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Programming with Microsoft Visual Basic th Edition
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 9 Structures and Sequential Access Files.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Chapter 9: Data types and data structures OCR Computing for A Level © Hodder Education 2009.
Tutorial 8: Manipulating Strings1 Tutorial 8 Manipulating Strings.
Microsoft Visual Basic 2008: Reloaded Third Edition
Chapter 9: Value-Returning Functions
A variable is a name for a value stored in memory.
Microsoft Visual Basic 2005: Reloaded Second Edition
VBA - Excel VBA is Visual Basic for Applications
Chapter 1: An Introduction to Visual Basic 2015
Strings, StringBuilder, and Character
Containers and Lists CIS 40 – Introduction to Programming in Python
Chapter 3: Using Variables and Constants
Chapter 7 Part 1 Edited by JJ Shepherd
The Selection Structure
Primitive Types Vs. Reference Types, Strings, Enumerations
The relational operators
Chapter 7: Strings and Characters
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
© Akhilesh Bajaj, All rights reserved.
Chapter 3: Introduction to Problem Solving and Control Statements
CIS16 Application Development Programming with Visual Basic
Object Oriented Programming in java
CIS16 Application Development and Programming using Visual Basic.net
CIS 16 Application Development Programming with Visual Basic
String Manipulation and More Controls
Tutorial 9 Sequential Access Files and Printing
Microsoft Visual Basic 2005: Reloaded Second Edition
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS16 Application Development and Programming using Visual Basic.net
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
CIS16 Application Development and Programming using Visual Basic.net
Topics Basic String Operations String Slicing
Topics Basic String Operations String Slicing
Presentation transcript:

CIS16 Application Development and Programming using Visual Basic.net Chapter 7 String Manipulation and Menus

Objectives After studying Lesson A, you should be able to: Determine the number of characters in a string Remove characters from a string Insert characters in a string Align the characters in a string Search a string Access the characters in a string Compare strings using pattern matching

Lesson B Objectives After studying Lesson B, you should be able to: Include a MenuStrip control on a form Add elements to a menu Assign access keys to menu elements Enable and disable a control Assign shortcut keys to commonly used menu items Code a menu item’s Click event procedure Include the Like operator in a procedure

Lesson C Objectives Include the Length property in a procedure After studying Lesson C, you should be able to: Include the Length property in a procedure Include the Substring method in a procedure Include the Remove method in a procedure Include the Insert method in a procedure Include the Contains method in a procedure

String Class Applications often need to manipulate string data There are many scenarios involving string manipulation: Determine the first character of an inventory part number Search an address to find a street name Make sure an email address is properly formatted String any set of alphanumeric input key to working with strings is to know what methods are available

String methods (cont'd.)

Determining the Number of Characters in a String Length property Stores the number of characters contained in a string Syntax: string.Length Returns an integer value

Working with Strings Determining the Number of Characters in a String Length Property Contains the number of characters in a string

Removing Characters from a String Trim Method Removes (trims) any space characters from both the beginning and end of a string Remove Method Removes a specified number of characters located anywhere in a string The computer makes a temporary copy of the string in memory, and then performs the specified removal on the copy The original string is not changed The modified copy is returned to the program

Removing Characters from a String (cont'd.)

Removing Characters from a String (cont.) The Product ID Application Figure 8-7 Sample run of the Product ID application

Inserting Characters in a String Insert method Inserts characters anywhere in a string The computer makes a temporary copy of a string and inserts specified characters into the copy Returns a string with the appropriate characters inserted startIndex argument An integer specifying the starting location to insert the value Represents the position in a string To insert the value at the beginning of a string, use a startIndex of 0

Inserting Characters into a String Insert Method Allows you to insert characters anywhere in a string

Inserting Characters in a String (cont.) Aligning the Characters in a String PadLeft method Inserts zero or more characters at the beginning of a string Results in a string of a specified length Right-aligns the characters within the string PadRight method Inserts characters at the end of the string Left-aligns the characters within the string

Searching a String (cont'd.) Contains Method Returns the Boolean value True when the subString is contained anywhere in the string IndexOf Method Returns an integer: either –1 or a number that is greater than or equal to 0 The –1 indicates that the subString is not contained in the string A number other than –1 is the character index of the subString’s starting position in the string

Inserting Characters in a String (cont.) Aligning the Characters in a String (cont.)

Searching a String Contains method Used to search a string to find a specific sequence of characters Returns a Boolean value True if found False otherwise You must specify the characters you are searching for The search begins with the first character in the string

Searching a String (cont.) IndexOf method Determines if a string contains a character sequence Returns an integer specifying the start position of a found character sequence (substring) If the substring is not found, the method returns -1 You must specify the sequence of characters to search for You may specify the index of the character at which to begin the search If not specified, the search begins with the first character in the string

Searching a String

Searching a String (cont'd.)

Searching a String (cont.) The City and State Application Allows the user to enter a string Composed of a city name, a comma, a space, and a state name Displays index of the comma in the string

Accessing the Characters in a String Substring method Used to access any number of characters in a string Returns a string with a specified number of characters Specify the index of the first character to access in the string, and the number of characters to retrieve If the number of characters is not specified, the method returns all characters from the startIndex position to the end of the string

Accessing the Characters in a String Substring Method Accesses any number of characters in a string

Accessing the Characters in a String (cont.) The Rearrange Name Application Allows the user to enter a first name, a space, and a last name Displays the name as last name, comma, space, first name

Accessing the Characters in a String (cont.) The Rearrange Name Application (cont.) Figure 8-17 Interface showing the rearranged name Figure 8-16 btnRearrange_Click procedure

Using Pattern-Matching to Compare Strings Like operator Allows the use of pattern-matching characters to determine whether one string is equal to another You must specify the string to be examined and the pattern to be matched The pattern can contain pattern-matching characters Returns a Boolean value True if a match is made False otherwise

Using Pattern Matching to Compare Strings Like Operator Allows you to use pattern-matching characters to determine whether one string is equal to another string

Using Pattern Matching to Compare Strings (cont'd.)

Using Pattern Matching to Compare Strings (cont'd.)

Using Pattern Matching to Compare Strings (cont'd.)

Random Numbers Random numbers are used in many computer game programs. The numbers can be integers or real numbers, which are numbers with a decimal place. Most programming languages provide a pseudo-random number generator is a mathematical algorithm that produces a sequence of numbers. numbers are not completely random, they are sufficiently random for practical purposes.

Random Class Random class must be instantiated to use its methods Methods allowing you to retrieve the next number produced by the random number generator: NextDouble() method returns a double random number between 0.0 and 1.0 Next() method returns an integer random number between two integer values NextBytes() method fills the elements of a specified array of bytes with random numbers. Syntax: dim objRnd as new Random

Seeding the random number generator Obtain random value when instantiated dim objRnd as new Random(50) Obtain random value using the method objRnd.Next() objRnd.Next(50,100) objRnd.Next(2000)

Code example – generates a number between 1 and 10 dim objRnd as new Random Dim intRandomNum as Integer intRandomNum = objRnd.next(1,11)