Lecture Set 6 The String and DateTime Data Types

Slides:



Advertisements
Similar presentations
The ArrayList Class and the enum Keyword
Advertisements

Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Java Programming Strings Chapter 7.
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
Lists Introduction to Computing Science and Programming I.
An Introduction to Programming with C++ Fifth Edition Chapter 12 String Manipulation.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Data Types 1.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Chapter 7: Characters, Strings, and the StringBuilder.
Vladimir Misic: Characters and Strings1Tuesday, 9:39 AM Characters and Strings.
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 And other things. Strings Overview The String Class and its methods The char data type and Character class StringBuilder, StringTokenizer classes.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Lecture 2 Review of 1301 and C# Richard Gesick. Common data types int, long, double, float, char, bool, string.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Strings A string is a sequence of characters that is treated as a single value. Strings are objects. We have been using strings all along. For example,
Lecture Set 6 The String and DateTime Data Types Part B – Characters and Strings String Properties and Methods.
Introduction to Programming Lecture 3 Msury Mahunnah, Department of Informatics, Tallinn University of Technology.
Expressions.
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
Programming Fundamentals
String String Builder.
© 2016, Mike Murach & Associates, Inc.
Java Review: Reference Types
Microsoft Visual Basic 2005 BASICS
Lecture Set 4 Data Types and Variables
Data Types and Variables Part D – Common Methods (ToString and Parse)
Variables and Arithmetic Operations
String and StringBuilder
Object Oriented Programming (OOP) LAB # 8
Topics Introduction to File Input and Output
Unit-2 Objects and Classes
String and StringBuilder
Part A – Doing Your Own Input Validation with Simple VB Tools
Week 9 – Lesson 1 Arrays – Character Strings
CIS16 Application Development Programming with Visual Basic
Part B – Structured Exception Handling
Microsoft Visual Basic 2005 BASICS
Arrays and Collections
Operator overloading Dr. Bhargavi Goswami
Topics Sequences Introduction to Lists List Slicing
Topics discussed in this section:
Learning VB2005 language (basics)
String and StringBuilder
Topics Sequences Lists Copying Lists Processing Lists
Topics Sequences Introduction to Lists List Slicing
Visual Programming COMP-315
Input, Variables, and Mathematical Expressions
Topics Introduction to File Input and Output
Trainer: Bach Ngoc Toan– TEDU Website:
Lecture 1 Review of 1301/1321 CSE /26/2018.
Presentation transcript:

Lecture Set 6 The String and DateTime Data Types Part C – String and Data Validation The StringBuilder class

Objectives Get an introduction to concept of data validation Gaining greater flexibility in manipulating strings with strings of the StringBuilder type 11/29/2018 12:55 AM

Validating User Entries We will later learn a lot more about user input validation when we cover the material on handling exceptions and input validation For now we provide a short introduction to the concept of input validation There are lots of ways in which users provide input through a form but one important one is through the use of a textbox User enters textual information (a string) This string is most often then converted to some internal form such as a number or date 11/29/2018 12:55 AM

Converting Textbox String Input We have several ways to convert a string to a value The Parse common method Decimal.Parse(salesString) Casting operators such as (int),(double) etc. (DateTime)txtDueDate.Text Methods associated with each type, such as ToDouble, ToInt32, and ToString System.Convert.ToDouble(myAge) The question is – when you use one of these approaches, how do you know whether the input string is properly structured for the requested conversion? IsDecimal, IsDate, IsNumeric exist in VB but in C# you have to write your own 11/29/2018 12:55 AM

StringBuilder Class Used to create mutable strings as opposed to the immutable ones we have seen so far. For immutable strings, when the value (and usually the length) is changed, the old string is deleted and a new one of the correct length is created. Always use this class when you are working with strings and doing inserts, replacements, appends, and removals. Why?  11/29/2018 12:55 AM

StringBuilder Class – how it works The StringBuilder type always retains the original memory initially allocated to a string. If you do not specify the capacity of a string when you declare it as of type StringBuilder, you get a string of capacity 16 If you assign a string data value having a length that is larger than a string variable’s capacity, StringBuilder adds to the capacity of the string variable – it doubles its capacity StringBuilder is just another data type You need using System.Text. 11/29/2018 12:55 AM

StringBuilder Functions (read all about them) The String and StringBuilder classes provide all the methods you need in working with strings (you can look them up – just use the correct notations in calling them) Creating a StringBuilder object with 0, 1, or 2 arguments – (initial value and / or length) StringBuilder phone = new StringBuilder(“2156352585”, 10); 11/29/2018 12:55 AM