Georgia Institute of Technology Creating and Modifying Text part 1 Barb Ericson Georgia Institute of Technology Oct 2005.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Character and String definitions, algorithms, library functions Characters and Strings.
HTML Minute University Richard Fisher 10/1/2001 HTML FSA Training2 HTML Overview  HTML  HyperText Markup Language.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Introduction to Computers and Programming Lecture 7:
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
String Escape Sequences
Basics of HTML Shashanka Rao. Learning Objectives 1. HTML Overview 2. Head, Body, Title and Meta Elements 3.Heading, Paragraph Elements and Special Characters.
Georgia Institute of Technology Introduction to Java part 2 Barb Ericson Georgia Institute of Technology May 2006.
Creating a Simple Page: HTML Overview
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Georgia Institute of Technology Introduction to Programming Part 2 Barb Ericson Georgia Institute of Technology May 2006.
Georgia Institute of Technology Introduction to Media Computation Barb Ericson Georgia Institute of Technology May 2006.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Lecture # 3 HTML and Arrays. Today Questions: From notes/reading/life? From Lab # 2 – Preview of Lab # 2 1.Introduce: How do you make a Web Page?: HTML.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
C Tokens Identifiers Keywords Constants Operators Special symbols.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Chapter 2: Java Fundamentals
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2005.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Georgia Institute of Technology Making Text for the Web Barb Ericson Georgia Institute of Technology March 2006.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Java Programming Java Basics. Data Types Java has two main categories of data types: –Primitive data types Built in data types Many very similar to C++
Copyright Curt Hill Variables What are they? Why do we need them?
PROCESSING Types. Objectives Be able to convert between binary and decimal numbers. Be able to declare and initialize character variables and constants.
HTML. Hyper Text Markup Language Markup your text document The markup is the tag Hyper text means you can jump from place to place.
Strings And other things. Strings Overview The String Class and its methods The char data type and Character class StringBuilder, StringTokenizer classes.
CreatingClasses-SlideShow-part41 Creating Classes part 4 Barb Ericson Georgia Institute of Technology Dec 2009.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
HTML HyperText Markup Language. Text Files An array of bytes stored on disk Each element of the array is a text character A text editor is a user program.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
HTML. Hyper Text Markup Language Markup your text document The markup is the tag Hyper text means you can jump from place to place Programming language.
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
Chapter 8 Adding Multimedia Content to Web Pages HTML5 & CSS 7 th Edition.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Click to edit Master text styles Stacks Data Structure.
Georgia Institute of Technology Introduction to Java, and DrJava part 1 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology.
Object Oriented Programming Lecture 2: BallWorld.
Georgia Institute of Technology Creating and Modifying Text Barb Ericson Georgia Institute of Technology June 2005.
Introduction to Java part 2
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
A guide to HTML.
Unit-2 Objects and Classes
WEB PROGRAMMING JavaScript.
Introduction to Java part 2
An overview of Java, Data types and variables
Introduction to Java, and DrJava part 1
What is HTML?.
Introduction to Java, and DrJava
Introduction to Java part 2
Introduction to Computer Science
Creating and Modifying Text part 3
Unit 3: Variables in Java
Introduction to Java, and DrJava
Introduction to Java, and DrJava part 1
Presentation transcript:

Georgia Institute of Technology Creating and Modifying Text part 1 Barb Ericson Georgia Institute of Technology Oct 2005

Georgia Institute of Technology Learning Goals Text as unimedia What is Unicode? The String class String methods Parsing a delimited string Converting from a string to a number

Georgia Institute of Technology Text as Unimedia Computers only understand 0 and 1 –On and off of voltage But we can store anything with that –Text, Pictures, Sounds, Movies, HTML pages We can do the same with Text –Convert a picture to text –Convert a sound to text HTML is a textual language –That is used to show pictures and play sounds

Georgia Institute of Technology HTML Open a browser and go to any web page –Go to the View menu and click on Source –What you see is HTML HTML is HyperText Markup Language –Uses special tags to denote sections of a document – This is the Title – This tag starts a new paragraph – This tag means to show this in bold

Georgia Institute of Technology java.lang.String Text in Java is stored as a String object –In Unicode format 2 bytes per character (16 bits) Matches ASCII for the first 128 characters A string literal is enclosed in double quotes –String message = "Hi There"; To add a double quote to a string –Use \“ > String s = "She said, \"Hi there\""; > System.out.println(s); She said, "Hi there“ Other special characters: –\n for new line –\t for tab

Georgia Institute of Technology Unicode International standard for character representation –Characters from all the major world languages Latin, Japanese, Chinese, etc –To see the decimal value for a Unicode character int temp = ‘a’; System.out.println(temp); –To create a character from a decimal value char a = (char) 65;

Georgia Institute of Technology Strings are Sequences of Characters You can get the character at an index –Starting with index 0 stringObj.charAt(index); Try this: > String test = “Hello”; > System.out.println(test.charAt(0)); > System.out.println(test.charAt(4));  How would you get the second character? H e l l o 01234

Georgia Institute of Technology String Methods Open the Java API –Click on the java.lang package –Click on the String class Look at the methods –Which will return part of a string? –Which will return the first index of a list of characters in the string? –While will return the last index of a list of characters? –Which will remove extra space before and after any other characters? –Which will return an array of String objects By chopping the string up into substrings Based on specified delimiters (like spaces or commas)

Georgia Institute of Technology Exercise How would you put the following in a string in Java? –She said, “I will see you later”. Create a short message and encode it using Unicode. – The numbers under each character are in hexidecimal –Give it to another student to decode it How could you pull out “be” from the string “I will be back”?

Georgia Institute of Technology Working with Delimited Strings Sometimes you get information about an object –In the form of a delimited string Jane Dorda :88, 92, 95, 87, 93, 85 Mike Koziatek :75, 92, 83, 81, 91, 87 Sharquita Edwards:91, 93, 95, 92, 94, 99 Here the delimiters are a colon after the name and commas between the grades

Georgia Institute of Technology Parsing a Delimited String Add another constructor to the Student class –That takes a delimited string Name : grade1, grade2, grade3, grade4, grade5 Use the split method to get an array of Strings –First based on the colon delimiter –Use trim to clear off any additional space from the name The first element in the returned array Use the split method again to get the array of grades as strings –Use the comma as the delimiter Use Double.parseDouble to translate the grade string into a double value –For the grade array

Georgia Institute of Technology Converting to a Number Strings are stored in Unicode format –Two bytes per character Integers are stored in 4 bytes (32 bits) You need to convert a number that is represented as a string into the number representation The wrapper classes have methods to do this –Integer.parseInt(numStr) The string “1234” is stored in 8 bytes With each character taking 2 bytes The integer 1234 is stored in 4 bytes | | | | | | | | |

Georgia Institute of Technology Constructor that takes a Delimited String public Student(String delimString, String nameDelim, String gradeDelim) { // split string based on name delimiter String[] splitArray = delimString.split(nameDelim); this.name = splitArray[0].trim(); // get the grade string and break it and convert to double String grades = splitArray[1]; String[] gradeStrArray = null;

Georgia Institute of Technology Constructor - continued if (grades != null) { gradeStrArray = grades.split(gradeDelim); this.gradeArray = new double[gradeStrArray.length]; for (int i = 0; i < gradeStrArray.length; i++) this.gradeArray[i] = Double.parseDouble(gradeStrArray[i]); }

Georgia Institute of Technology Testing the Constructor Write a main method that will create a Student object and initialize the name and grade array –From a delimited string Run the main method from DrJava Use the Debugger to walk through the constructor

Georgia Institute of Technology Summary All media can be saved as text Text in Java is stored in String objects –java.lang.String Use the API to find all the methods for String objects –Or methods for any Java class You can use the split method to parse delimited text You can use Double.parseDouble(string) –To get a double from a String object