Formatting and Parsing. Slide 2 Introduction Two core topics Parsing - Converting strings to other types (numbers, dates, …) Formatting Converting those.

Slides:



Advertisements
Similar presentations
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Advertisements

Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
The Print Formatting Statement … named printf. 2 Introduction to printf statements print and println statements don’t allow us to easily format output.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include #include int main ( ) { printf( "%d\n", 455 ); printf( "%d\n", 455 ); printf(
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Printing. printf: formatted printing So far we have just been copying stuff from standard-in, files, pipes, etc to the screen or another file. Say I have.
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
CIS 270—Application Development II Chapter 28—Formatted Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
February 2006Colby College ITS Formatting Techniques for Excel 2003.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
CSC 162 Visual Basic I Programming. Randomizing and Formatting Randomizing Formatting –User-Defined Formats –Named Numeric Formats.
Introducing Python CS 4320, SPRING Format: Field widths and Alignment The string representation of a value can be padded out to a specific width.
1.3 Console Input And Output academy.zariba.com 1.
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
1 Pertemuan 4 Fungsi-Fungsi Bahasa C Matakuliah: T0016/Algoritma dan Pemrograman Tahun: 2005 Versi: versi 2.
WHAT IS A DATABASE? A DATABASE IS A COLLECTION OF DATA RELATED TO A PARTICULAR TOPIC OR PURPOSE OR TO PUT IT SIMPLY A GENERAL PURPOSE CONTAINER FOR STORING.
Dale Roberts Basic I/O (Chap. 9) CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
ASNApalooza 2007 © Copyright 2007 by ASNA. All rights reserved. by Mike Marlowe ASNA Instructor/Pre-Sales Engineer © Copyright 2007 by ASNA. All rights.
Introduction to Database using Microsoft Access 2013 Part 6.1 November 18, 2014.
Operations on Strings. 8/8/2005 Copyright 2006, by the authors of these slides, and Ateneo de Manila University. All rights reserved L: String Manipulation.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
ASNApalooza 2007 © Copyright 2007 by ASNA. All rights reserved. by Mike Marlowe ASNA Instructor/Pre-Sales Engineer © Copyright 2007 by ASNA. All rights.
Strings And other things. Strings Overview The String Class and its methods The char data type and Character class StringBuilder, StringTokenizer classes.
Standard I/O Functions – printf() Without specifying any display formatting, the printf() function will use DEFAULT setting: Print in a field of minimum.
String Formatting Preparing strings for output. Printing println( arg ) prints its one argument on a line println can be used to print any single value,
Data types S S T : S P R E A D S H E E T S SST 2 Spreadsheet 2 Data Types Name: ______________________ Class: ______________________.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
Formatted Output CSE 1310 – Introduction to Computers and Programming 1.
CS 1704 Introduction to Data Structures and Software Engineering.
Microsoft Access Prepared by the Academic Faculty Members of IT.
MODULE 4.1: INTRODUCTION TO SPREADSHEETS. CONTENTS What is a spreadsheet? Basic functions Inputting data Use of formatting More about different types.
INTRODUCTION TO DATABASE USING MICROSOFT ACCESS 2013 Part 5.1 November 16, 2014.
28 Formatted Output.
Chapter 9 - Formatted Input/Output
Creating Database Objects
C Formatted Input/Output
Formatted Input and Output
Using the Console.
© 2016, Mike Murach & Associates, Inc.
TMF1414 Introduction to Programming
© 2016, Mike Murach & Associates, Inc.
Input and Output Lecture 4.
Data Types and Variables Part D – Common Methods (ToString and Parse)
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Lecture 13 Input/Output Files.
Chapter 9 - Formatted Input/Output
CSI 101 Elements of Computing Spring 2009
Department of Computer and Information Science
Introduction to Java Applications
Data Types and Expressions
Converting Fractions, Decimals, & Percentages
Creating Database Objects
Presentation transcript:

Formatting and Parsing

Slide 2 Introduction Two core topics Parsing - Converting strings to other types (numbers, dates, …) Formatting Converting those same other types back to strings

Slide 3 Formatting You have seen how to call ToString() to format a number or date Here, we delve much deeper into formatting

Slide 4 Formatting Numeric Values as Strings There are a couple of ways to format data Call the String.Format method The first argument contains the “format string” The second argument contains the value to format Call the ToString() method of a numeric or DateTime data type

Slide 5 Formatting Numeric Values as Strings (2) Applying custom formatting Use predefined format strings Use the NumberFormatInfo

Slide 6 The NumberFormatInfo Class Culture invariant information to format and parse numbers Properties To define currency formatting characters and precisions Separators (decimal / percent) Positive / negative pattern and sign

Slide 7 String.Format A format string contains Literal text, Placeholders that contain the formatted values Placeholders have the syntax {index[,alignment][:formatString]} index is a value from 0 to n marking the placeholder number alignment contains the minimum width of the formatted value Negative values are left justified format string contains the format specifiers

Slide 8 String.Format (Example) s = String.Format( "(C) Currency: {0:C}\n" + "(D) Decimal: {0:D}\n" + "(E) Scientific: {1:E}\n" + "(F) Fixed point: {1:F}\n" + "(G) General: {0:G}\n" + " (default): {0} (default = 'G')\n" + "(N) Number: {0:N}\n" + "(P) Percent: {1:P}\n" + "(R) Round-trip: {1:R}\n" + "(X) Hexadecimal: {0:X}\n", -123, f); Console.WriteLine(s);

Slide 9 Using ToString() Call ToString on the numeric data type The format specifier is passed as an argument Example: txtOutputString.Text = i.ToString(“0:C”);