Strings PART I STRINGS, DATES, AND TIMES. FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI)

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

CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
Manipulating Strings String Functions. VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Slide 1 VB Programming Fundamentals. Slide 2 Visual Basic Language v VB language is powerful and easy to use v Descendent of BASIC (Beginner's All-Purpose.
1 Pertemuan 04 Expression Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Strings in Visual Basic Words, Phrases, and Spaces.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
Fundamental Programming Structures in Java: Strings.
JavaScript, Third Edition
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
On to… string operations & functions. Concatenation (&) §When we want to combine two character strings into one new (longer) string, we can concatenate.
BACS 287 Visual Basic String Manipulation. BACS 287 Visual Basic Strings In Visual Basic, a “string” is a series of text, numbers, and special characters.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Ten String Manipulation and Menus.
1.
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
Strings PART II STRING$ AND SPACE$. Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example:
Manipulation Masterclass By the VB Gods. In this masterclass, we will learn how to use some of the string manipulation function such as Len, Right, Left,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Characters In Java, single characters are represented.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
Chapter 2: Using Data.
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
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.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Instructor: Craig Duckett Lecture 08: Thursday, October 22 nd, 2015 Patterns, Order of Evaluation, Concatenation, Substrings, Trim, Position 1 BIT275:
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
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.
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
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.
Chapter 2 Variables.
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
1 STRINGS String data type Basic operations on strings String functions String procedures.
C++ String Class nalhareqi©2012. string u The string is any sequence of characters u To use strings, you need to include the header u The string is one.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
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.
Characters and Strings
02/03/ Strings Left, Right and Trim. 202/03/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
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.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
13/06/ Strings Left, Right and Trim. 213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
Microsoft Visual Basic 2008: Reloaded Third Edition
Chapter 2 Variables.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
JavaScript Objects.
Primitive Types Vs. Reference Types, Strings, Enumerations
SQL Text Manipulation Farrokh Alemi, Ph.D.
Chapter 2 Variables.
CS 106 Computing Fundamentals II Chapter 66 “Working With Strings”
Sub Procedures and Functions
VBScript Session 10.
Introduction to Computer Science
Chapter 2 Variables.
What We Want To Do User enters: Mary Smith
Presentation transcript:

Strings PART I STRINGS, DATES, AND TIMES

FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI) Character Set Small integer values 0 to 127(1st 128 ANSI Characters) equal American Standard Code for Information Interchange(ASCII) Strings are series of characters treated as single unit include: letters, numbers, special characters, and others (special VB data type)

FUNDAMENTALS OF CHARATERS AND STRINGS String literals or string constants indicated by double quotes Example: “John Q. Doe” “9999 Main Street” “Somewhere, Massachusetts” “(555) ” Dollar sign is type declaration character for String String data type: declares string variables

FUNDAMENTALS OF CHARATERS AND STRINGS Types of strings: 1. variable-length (default) 2. fixed-length Consists of characters with numeric values, range 0 to 255 grow and shrink dynamically Example: Variable-length Dim s As String s = “blue”

FUNDAMENTALS OF CHARATERS AND STRINGS Example: Fixed length Dim SocialSecurityNumber As String * 11 SocialSecurityNumber = “ ” String Concatenation with & and + : combine smaller strings into one Example: s1 = “Pro” s2 = “gram” s3 = s1 & s2 output=program or s3 = s1 + s2

FUNDAMENTALS OF CHARATERS AND STRINGS Problem: s1 = “hello” + 22 would attempt convert hello to number and add 22 resulting in type mismatch Rule of thumb: use & for concatenation Comparing Character Strings: use: relational operators (, =) equality operators (<>, =)

FUNDAMENTALS OF CHARATERS AND STRINGS StrComp function: returns: 0 if strings are equal -1 if 1st string is < 2nd string 1 if 1st string is > 2nd string Comparisons are made based on numeric values (ASCII) associated with characters Function StrComp has an optional 3rd argument: indicates comparison type

FUNDAMENTALS OF CHARATERS AND STRINGS Option Compare type (module-level statement) type: Binary, Text, or Database Option Compare not used: default is Binary Strings of different length: Example: “j” VS. “john” if one name is equivalent to leftmost portion of another name, shorter name comes before longer name

FUNDAMENTALS OF CHARATERS AND STRINGS Operator Like another comparison of two strings compare patterns of characters as well as strings Example: “HBLT55DD” Like “HBLT55DD” True or False test “HBLT55DD” Like “HBLT*” asterisk is pattern matching character any number of characters can follow

FUNDAMENTALS OF CHARATERS AND STRINGS question mark- single character can be any type of character pound sign- single character can be a digit Example: “HBLT55DD” Like “?#LT55DD” (false) “HBLT55DD” Like “?BLT##DD” (true) square brackets- series of characters provided for matching characters Example: “HBLT55DD” Like “H[A-F]LT55DD” “HBLT55DD” Like “H[A-F]LT[!4-7]5DD” [!] not

MANUIPULATING INDIVIDUAL CHARACTERS Code example: Figure 8.3, p. 310 Mid$ - allows programmer to extract one character at a time from a string Example: Figure 8.4, p. 311 Mid$ used with phrase to extract one character at a time in reverse Note1: program also uses Len function to determine length of phrase

MANUIPULATING INDIVIDUAL CHARACTERS Mid$ Function Arguments: 1. Source string from which substring will be selected 2. Starting character position in string 3. Number of characters to select Note2: if last argument is omitted or number of characters remaining is less than number of characters, remainder of string from starting character position is returned

MANUIPULATING INDIVIDUAL CHARACTERS Example: phrase = txtInput.Text txtOutput.Text = txtOutput.Text & _ Mid$ (phrase, position, 1) Note3: can be used to replace portion of string with another string Example: x =“Visual Basic 6!” Mid$ (x,2,3) = “xxx” x changed to “Vxxxal Basic 6!”

LEFT$,RIGHT$, AND INSTR Left$ selects left most portion of string Example: s1=“ABCDEF” s2=“Left$(s1,4) Assigns leftmost four character to s2 s2 = “ABCD” Right$ selects rightmost portion of string s1 = “ABCDEF” s2 = Right$(s1,4) Assigns rigthmost four characters to s2

LEFT$,RIGHT$, AND INSTR s2 = “CDEF” InStr search through one string (base string) to determine if it contains another string (search string) When found, starting character location of string is returned Should second string contain no character (0 length), starting position is returned Example: s1 = “AEIOU” s2 = “IOU”

LEFT$,RIGHT$, AND INSTR result = InStr(1, s1, s2) result = “IOU” (starts search at position 1 of s1) Note1: If InStr determines search string is not contained within base string, returns zero Example: result = InStr(1, “aeiou”, “aeb”) result = InStr(4, “aeiou”, “iou”) result = InStr(1, “aeiou”, “aeiouy”) result = 0 for all three cases

LEFT$,RIGHT$, AND INSTR (1) blankPosition = InStr(1, phrase, “ “) returns first blank position in phrase (2) nextWord = Left$(phrase, blankPosition - 1) picks off one word at a time from phrase and assigned to nextWord (3) phrase = Right$(phrase, Len(phrase) - blankPosition)

LEFT$,RIGHT$, AND INSTR returns remainder of phrase from character after blankPosition Note2: eventually phrase shrinks to one word Searching for Substrings in Strings Using InStr and InstrRev: search for substrings in a string from beginning to end of string InStr searches from any location in a string InStrRev search from end or any other position

Searching for Substrings in Strings Using InStr and InstrRev InStrRev’s arguments: (1) base string (2) search string (3) starting character position in base string Outcome” (1) if search string found, starting character location of string is returned (2) if search string is zero length, starting position is returned

Searching for Substrings in Strings Using InStr and InstrRev Example1: Dim s1 As string, s2 As string s1 = “abcdefghijklmnop” s2 = “m” result = InStrRev (s1, s2, Len (s1)) determines s2 is in s1 at position 13 return 13 as starting position (s2 in s1) 13 is assigned to result Len (s1)- s2 begins at end of s1

Searching for Substrings in Strings Using InStr and InstrRev Note: third argument can be omitted if search begins from end of base string if string not contained in base string, returns 0 Example2: result = InStr(“aeiou”, “aeb”) result = InStr(“aeiou”, “iou”, 2) resutl = InStr(“aeiou”, “aeiouy”) fowardResult = InStr(Input1, Input2) locates 1st occurrence of Input2 in Input1

Searching for Substrings in Strings Using InStr and InstrRev backwardResult = InStrRev(txtInput1.Text, txtInput2.Text) locates last occurrence of txtInput2.Text in txtInput1.Text starting from end of txtInput1 LTrim$, Rtrim$, Trim$: (1) remove leading spaces from left side of string (2) remove trailing spaces from right side of string (3) remove spaces on left and right side of string

Ltrim$, Rtrim$, Trim$ Useful for removing extra space characters used to pad a fixed-length string string would occupy space allocated String$ and Space$: create strings of specified number of characters String$ creates string of specified character Space$ creates string of spaces