Strings PART II STRING$ AND SPACE$. Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example:

Slides:



Advertisements
Similar presentations
Objectives After completing this lesson, you should be able to do the following: Describe various types of conversion functions that are available in.
Advertisements

Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
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.
Data types and variables
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
On to… string operations & functions. Concatenation (&) §When we want to combine two character strings into one new (longer) string, we can concatenate.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Objectives You should be able to describe: Data Types
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Dani Vainstein1 VBScript Session 9. Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables,
Variables and Constants
© 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.
CS0004: Introduction to Programming Input and Output.
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.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Intrinsic Functions Pre-coded Functions Used to improve developer productivity Broad Range of Activities Math calculations Time/Date functions String.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
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.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Input, Output, and Processing
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
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.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Manipulating Strings. What is a string? Data composed of text characters. The data is stored in consecutive bytes of memory. Each byte stores the ASCII.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
1 Microsoft® Visual Basic®.NET Language # 1. 2 Variable Declaring Variable Dim {VariableName} As {Type} Dim {VariableName} As {Type} = {value} Example:
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Formatting Output. Formatting features of printf System.out.printf can perform the following Rounding floating-point values Aligning properly a column.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Strings PART I STRINGS, DATES, AND TIMES. FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI)
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 VB-06-String Manipulation Mar 03, 2002 String Function VISUAL BASIC.
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
INTRODUCTION TO DATABASE USING MICROSOFT ACCESS 2013 Part 5.1 November 16, 2014.
28 Formatted Output.
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Strings, StringBuilder, and Character
2.5 Another Java Application: Adding Integers
Formatting Output.
Numbers.
VBScript Session 10.
Introduction to Java Applications
Internal Functions.
Section 6 Primitive Data Types
Presentation transcript:

Strings PART II STRING$ AND SPACE$

Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example: string$(10, “A”) -creates 10 A’s string$(5, 97) -creates 5 a’s space$(5) & string$(5, “a”) -creates 5 spaces which are appended to 5 a’s

FUNCTION REPLACE Search string and replace with another string Example: lblOutput.Caption = Replace(txtInput.Text, “ “, “..”) replace blanks in txtInput.Text with 2 periods optional arguments: (4) indicate starting character position for search (5) specify number of replacements to perform (6) specifies comparison type -binary or text

FUNCTIONS STRREVERSE, UCASE, AND LCASE StrReverse: Reverses a string Example: txtOutput.Text = StrReverse(txtInput.Text) UCase converts string to upper case LCase converts string to lower case Examples: txtUpperCase.Text = UCase(txtInput.Text) txtLowerCase.Text = LCase(txtInput.Text)

CONVERSION FUNCTIONS: ASC AND CHR$ Asc returns ASCII code corresponding to a given character Example: Asc(“a”) returns 97 Note: if contains more than one character, returns ASCII code of first character only Chr$ returns string corresponding to ASCII code Example: Chr$(34) returns “ (double quotes)

CONVERSION FUNCTIONS: ISNUMERIC, VAL, AND STR$ IsNumeric- returns True if string is numeric Val-converts strings to numbers Str$-converts numbers to strings Example: If IsNumeric(txtInput.Text) Then lblOutput.Caption = txtInput.Text & “ + 10 is “ & Str$(Val(txtInput.Text) + 10) Note1: valid input to Val: 0-9, + or -, and. Note2: convert hexadecimal value preceded by &H Note3: convert octal values preceded by &O

FUNCTIONS: HEX$ AND OCT$ Hex$- converts numbers to hexadecimal (base 16) format strings Oct$- converts numbers to octal (base 8) format strings Example: txtHex.Text = Hex$(txtInput.Text) txtOct.Text = Oct$(txtInput.Text)

TYPE CONVERSION FUNCTIONS Note: conversion errors occur at run-time Cbool- convert string to Boolean (1) if numeric zero or string zero, returns False (2) all other numeric values or strings returns True Cbyte- convert string to value 0 to 255 nonnumeric values or strings result in error Ccur- convert string to Currency nonnumeric values or strings result in error

TYPE CONVERSION FUNCTIONS Cdate-convert string to a date value (numeric or string representation) CDb1-convert string to a Double value (double-precision, floating point) CDec-convert string to Decimal value CInt-convert string to Integer value CLng-convert string to Long Integer value Cvar-convert string to Variant : numeric=Double, non-numeric=string

STRING FORMATTING CStr-convert string depending on type: (1)date=short format date returned (2)boolean=True or False returned (3)number=corresponding number returned (4)error=corresponding error message returned (5)null=error occurs String Formatting: Format$ “General Number”-displays number with no separators for places beyond hundreds

STRING FORMATTING Format$ “Currency”-number with dollar symbol, separator for thousands, and two digits after decimal Format$ “Fixed”-number with at least one digit to left of decimal, and two to right Format$ “Standard”-separators for thousands, at least one digit to left of decimal and two to right Format$ “Scientific”-scientific notation with two digits to right of decimal

STRING FORMATTING Format$ “Percent”-multiplies number by 100, displays % to right and two digits right of decimal Format$ “Yes/No”-displays No if 0, Yes otherwise Format$ “True/False”-False if 0, Yes otherwise Format$ “On/Off”-Off if 0, On otherwise Formats are formed using strings containing formatting flags.

STRING FORMATTING Example 1: Use format flag 0 which represents a required digit and displayed as whole number (floating-point values are automatically rounded). Example 2: Use format flag 0 with “0.00” to insure at least one digit to left and two to right of decimal. Example 3: Use format flag # with “#,##0.00” # represents a digit place holder, if no digit present nothing is displayed; flag, invoked for thousands; two decimal places to right.

STRING FORMATTING Example 4: Use “$#,##0.00” which is same format except uses $ literal; valid literals:-,+,(,). Note: a blackslash (\) will allow other literals to be displayed that follow ; Example 5: Use “0%”output whole number percent. Example 6: Use “0.00%” output percent with two decimals to right. Example 7: Use “0.00E+00” scientific notation with at least two digits in the exponent; negative exponents displayed with – sign.

STRING FORMATTING Example 8: Demonstrating negative exponents- Format$( , “0.00E-00) Example 9: Demonstrating formats for non-negative and negative values: Format$( ,“$#,##0.00;($#,##0.00)”) Note: semi-colons used to separate formats and up to four formats can be used where third format is for zero values and the fourth is for null values Function FormatNumber- used to format values Arguments:(1)numeric expression,(2) digits right of decimal, (3)display leading zero or not, (4)whether or not parentheses displayed around negative numbers, (5)display or not thousands place separators (2-5 are optional)

STRING FORMATTING Function FormatCurrency: Arguments: (1) numeric value to format (2) number of digits to right of decimal (3) whether or not leading zero displayed (4) whether or not parentheses are placed around negative numbers (5) whether or not thousands separators are used (2-5 are optional)

STRING FORMATTING Function FormatPercent: Arguments: (1) numeric value to format (2) number of digits to right of decimal (3) whether or not leading zero displayed (4) whether or not parentheses are placed around negative numbers (5) whether or not thousands separators are used Note: 2-5 are optional

DATE AND TIME PROCESSING Function Now- current system date and time Example:”Current data and time: “ & Now Function Date- current system date Example:”Date: “ & Date Function Day- gives day of month 1-31 Example:”Day: “ & Day(Date) Function WeekDay- day of week as integer (1-7) Example:”Weekday: “ & WeekDay(Date) by default Sunday=1

DATE AND TIME PROCESSING Example: “WeekdayName: ” & WeekdayName(Weekday(Date)) where WeekdayName returns the string name of weekday Example: “WeekdayName: “ & WeekdayName(Weekday(Date), True) True indicates the abbreviated name should be returned (i.e. Sunday, Sun) Example: “Month: “ & Month(Date) returns 1-12 Example: “MonthName: ” & MonthName(Month(Date)) returns string name with January=1

DATE AND TIME PROCESSING Example: “MonthName abbreviated: & MonthName(Month(Date), True) where True returns the short name (i.e. Jan=January) Example: “Year: “ & Year(Date) returns year as integer Example: #3/2/1996# is a data literal and enclosed within two pound signs IsDate-use to determine if string can be converted to date Example: Format (IsDate(123456), “True/False”)

DATE AND TIME PROCESSING Note: the function recognizes dates in the range January 1, 1000 to December 31, 9999 Viable formats: January 1, 1999 Jan 1, /1/1999 1/1/99 1-Jan-99 1-Jan-1999

DATE AND TIME PROCESSING Function DateValue-convert a string into a date Example: “DateValue(“ ”) Viable formats: January 1, 1999 Jan 1, /1/1999 1/1/99 1-Jan-99 1-Jan-1999

DATE AND TIME PROCESSING Function DataSerial- create dates, receives three arguments: year, month, and day Example: DateSerial(1998, 8, 2) Function DatePart-receives two arguments: (1) a string to indicate part of date to return, (2) data expression Example: DatePart(“yyyy”, Now)-get year from current date and time returned by Now

DATE AND TIME PROCESSING Example Demonstrating adding and subtracting dates: “Days between now and 12/31/98: “ & DateDiff(“d”,Now,”12/31/98”) Function DateAdd- add to a date and has three arguments: (1) interval, (2) value to add, & (3) date interval is string indicating part of date modified string indicates 2nd argument should be added to year Function DateDiff- subtract dates and has three arguments: (1) interval, (2) 1st date, & (3) 2nd date

DATE AND TIME PROCESSING Optional arguments: (4) constant indicating day of week, (5) constant indicating 1st week of year Example: DateDiff(“d”, “1/1/98”, Now) Functions: Hour, Minute, Second, Timer (number of seconds since midnight) TimeSerial-return date containing specified time Arguments: (1) hour as value 0-23, (2) minute & (3) second – example: 90= 1 hour, and 30 minutes

DATE AND TIME PROCESSING Function TimeValue: returns date containing specified time. Range=0:00:00 AM-23:59:59 PM Function FormatDateTime: format current date and time as general date displaying date and time Arguments: (1) expression to format, (2) constant representing format Function Format: format current date and time Arguments: (1) expression to format, (2) string representing format

STRING ARRAYS Array whose elements are strings particular element or string within array if referred to by giving name of string followed by index Example: Dim a(1) As String, b As String a(0) = “Hello” a(1) = “There!” b = Join(a) Join is the concatenation function result=“HelloThere!”

STRING ARRAYS Function Filter-used to search String array a for “Visual Basic 6” Filter returns a string array that is assigned to array b Each element of b stores the string “Visual Basic 6” Sub PrintString then prints each element of b Erase is used to erase b’s memory 3rd argument is an optional Boolean value indicates whether or not 2nd argument included in filtering When False, 2nd argument is excluded

STRING ARRAYS Filter has a 4th optional argument determines type of comparison to use default is vbBinaryCompare, other values from Figure 8.2 can be used Visual Basic tokenization function Split is used to extract the words from a sentence Split extracts all substrings (or tokens) substring in this case is any character or group of characters separated by a space character(delimiter) Split(string, delimiter=“ “,counter=- 1,compare=vbBinaryCompare )