CIT 383: Administrative Scripting

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

LING 388: Language and Computers Sandiway Fong Lecture 3: 8/28.
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.
Scripting with Ruby What is a scripting language? What is Ruby?
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.3 The Class String.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting RSS.
String Escape Sequences
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting XML.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Introduction.
CIT 383: Administrative Scripting
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Writing Methods.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Methods and Hashes.
Chapter 5 Strings CSC1310 Fall Strings Stringordered storesrepresents String is an ordered collection of characters that stores and represents text-based.
Scripting with Ruby What is a scripting language? What is Ruby?
C++ Basics Tutorial 5 Constants. Topics Covered Literal Constants Defined Constants Declared Constants.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Regular Expressions.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting HTTP.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Numbers.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Strings CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Standard Types and Regular Expressions CS 480/680 – Comparative Languages.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting Directories.
CIT 383: Administrative Scripting
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting DateTime.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
Introduction to information systems RUBY dr inż. Tomasz Pieciukiewicz.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
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.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Java Variables and Types
ECE Application Programming
String class.
Ruby and other languages….
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
CIT 383: Administrative Scripting
University of Central Florida COP 3330 Object Oriented Programming
Scope, Objects, Strings, Numbers
Introduction to Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
MSIS 655 Advanced Business Applications Programming
CIT 383: Administrative Scripting
Introduction to C++ Programming
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
CIT 383: Administrative Scripting
Ruby Testing 2, 11/9/2004.
CMSC 202 Java Primer 2.
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
Java Programming Language
EECE.2160 ECE Application Programming
String methods 26-Apr-19.
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
CIT 383: Administrative Scripting
Instructor: Alexander Stoytchev
Perl Regular Expressions – Part 1
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

CIT 383: Administrative Scripting Strings and Variables CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Topics Single-quoted strings. Double-quoted strings. Choose your own quotes. Characters. String operators. CIT 383: Administrative Scripting

Single-quoted Strings Create strings using single quotes. ‘Hello ruby’ Escape ‘ using \ ‘O\’Reilly published Learning Ruby.’ ‘A \ is just itself in the middle.’ ‘This string ends with one backslash.\\’ ‘You can also have multi-line strings using \ to escape the newline character.’ CIT 383: Administrative Scripting

Double-quoted Strings Create strings using double quotes. “Hello Ruby” Double quoted strings have more escapes “Hello \”Rubyist\”” “A multi-\nline string.” “\tString indented by one tab.” “No need to use backslash to escape newlines in double quoted strings.” CIT 383: Administrative Scripting

CIT 383: Administrative Scripting String Escapes \f Form feed character (ASCII 12) \n Newline character (ASCII 10) \r Carriage return character (ASCII 13) \t Tab character (ASCII 9) \C-x Control-x character, i.e. \C-m is same as \r \nnn Byte represented by octal code from 000 to 377 \xnn Byte represented by hex code from 00 to FF \x The character x by itself, unless x is a newline or one of the special chars abcefnrstuvxCM01234567. Most commonly used to escape \, #, and “ CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Interpolation Include result of code in double-quoted string “1 + 1 == #{1+1}” x = 2*3.1415926 “360 degrees == #{x} radians” CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Choose your own Quotes If your string has a lot of ‘ or “ in it, you have to do a lot of escaping so ... Ruby allows you to choose your own quotes %q acts like single-quoted string %Q acts like double-quoted string Character after q or Q is the delimiter. Initial and final delimiters are identical unless you’re using one of a matched pair: (,[,{,< match ),],},> respectively. Examples %q(No need to worry about escaping ‘ here) %Q|Or for escaping “ in this string.| %Q|But you do have to escape \| here.| CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Here Documents For long string literals, any chosen delimiter may be used within the string, so Ruby can delimit text using arbitrary strings like bash. document = <<HERE <html><head> <title>Here Document!</title> </head><body> “A quoted body isn’t normal.” </body></html> HERE CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Here Documents Behave like double-quoted strings String interpolation Escape characters Single-quoted here documents: document = <<‘EOD’ You can use #{1+1} to escape ruby code, and you can use \t as backslash and t, as they don’t do anything special here. EOD CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Character Literals Single characters denoted by a ? prefix ?a is the character a ?” is the double-quote character ?\t is the tab character Not the same as a single character string ?a != ‘a’ CIT 383: Administrative Scripting

CIT 383: Administrative Scripting String Operators Concatenation “Hello” + “ “ + “Ruby” == “Hello Ruby” Converting numbers to strings version = 1.9 “Hello Ruby “ + version.to_s == “Hello Ruby 1.9” “Hello Ruby #{version}” Multiplication ellipsis = ‘.’*3 # Evaluates to ... CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Logical Operators Equality ‘Hello’ == ‘Hello’ Inequality ‘Hello’ != ‘hello’ Less Than ‘a’ <= ‘b’ Less Than or Equal To ‘a’ <= ‘a’ Greater Than ‘baz’ > ‘bar’ Greater Than or Equal To ‘baz’ >= ‘baz’ CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Accessing Characters Use index to access individual characters x = “Hello” x[0] == ?H x[1] == ?e Negative numbers index from the end x[-1] == ?o x[-2] == ?l Use index to modify string, -1 index special x[0] = ?M # changes x to Mello x[-1] = “” # changes to Mell CIT 383: Administrative Scripting

CIT 383: Administrative Scripting Substrings Use double index to access substrings x = “Hello” x[0,2] == “He” x[-2,2] == “lo” x[0,0] == “” # For all strings x[0,10] == “Hello” x[0,-1] == nil # Negative lens ret nil Modify string by assigning to index x[0,2] = “Ma” x[-2,2] = “ow” x == “Mallow” x[2,2] = “” x == “Maow” CIT 383: Administrative Scripting

CIT 383: Administrative Scripting References Michael Fitzgerald, Learning Ruby, O’Reilly, 2008. David Flanagan and Yukihiro Matsumoto, The Ruby Programming Language, O’Reilly, 2008. Hal Fulton, The Ruby Way, 2nd edition, Addison-Wesley, 2007. Dave Thomas with Chad Fowler and Andy Hunt, Programming Ruby, 2nd edition, Pragmatic Programmers, 2005. CIT 383: Administrative Scripting