13/06/20161 6.2 Strings Left, Right and Trim. 213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.

Slides:



Advertisements
Similar presentations
Manipulating Strings String Functions. VB provides a large number of functions that facilitate working with strings. These are found in Microsoft.VisualBasic.Strings.
Advertisements

Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
30/04/ Selection Nested If structures & Complex Multiple Conditions.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
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.
CS1100: Computer Science and Its Applications Text Processing Created By Martin Schedlbauer
1 Pertemuan 04 Expression Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Strings in Visual Basic Words, Phrases, and Spaces.
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.
1.
08/09/ Arrays Defining, Declaring & Processing.
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
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,
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Manipulating Text In today’s lesson we will look at: why we might want to pick out parts of text strings some BASIC functions that can be used to chop.
MS-Excel XP Lesson 6. NOW Function 1.Returns the current date and time formatted as a date and time. 2.A1  =NOW() 3.A2  Select Insert menu Select Function.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
String Manipulation. Strings have their own properties and methods, just like a textbox or label or form does.
30/10/ Iteration Loops Do While (condition is true) … Loop.
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.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 8: Fun with strings.
H2K Infosys is business based in Atlanta, Georgia – United States Providing Online IT training services world wide. USA - +1-(770) ,
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Processing Text Excel can not only be used to process numbers, but also text. This often involves taking apart (parsing) or putting together text values.
String Manipulation 10/21/2015 Lect#6 GC Strings have their own properties and methods, just like a textbox or label or form does. 10/21/2015 Lect#6.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 2 Karsten Hokamp, PhD Genetics TCD, 17/11/2015.
1 CSE 2337 Chapter 7 Organizing Data. 2 Overview Import unstructured data Concatenation Parse Create Excel Lists.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
GCSE Computing: Programming GCSE Programming Remembering Python.
02/03/ Strings Left, Right and Trim. 202/03/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
Strings PART I STRINGS, DATES, AND TIMES. FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI)
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
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.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 15 JavaScript.
The Methods and What You Need to Know for the AP Exam
String and Lists Dr. José M. Reyes Álamo.
Do-more Technical Training
String Methods Programming Guides.
Open Source Server Side Scripting MySQL Functions
Introduction to Programming
SQL Text Manipulation Farrokh Alemi, Ph.D.
Introduction to Programming
Manipulating Text In today’s lesson we will look at:
String Manipulation Chapter 7 Attaway MATLAB 4E.
CS 106 Computing Fundamentals II Chapter 66 “Working With Strings”
Do While (condition is true) … Loop
4.1 Strings ASCII & Processing Strings with the Functions
String and Lists Dr. José M. Reyes Álamo.
Sub Procedures and Functions
VBScript Session 10.
Introduction to Programming
Fundamentals of Python: First Programs
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Introduction to Computer Science
Introduction to Programming
MapInfo SQL String Functions
Python Strings.
Presentation transcript:

13/06/ Strings Left, Right and Trim

213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.

Left returns a substring from the main string starting with the first character up to a specified length. Right returns a substring from the main string starting with last character up to a specified length. Dim Message As String Dim Message As String Message = “ Printers are not expensive ” Message = “ Printers are not expensive ” lblLeft.Text = “The first 5 characters are: ” lblLeft.Text = “The first 5 characters are: ” & Microsoft.VisualBasic. (Message, ) & Microsoft.VisualBasic. (Message, ) lblRight.Text = “The last 7 characters are: ” lblRight.Text = “The last 7 characters are: ” & Microsoft.VisualBasic. (Message, ) & Microsoft.VisualBasic. (Message, ) 313/06/2016 Breaking strings with Left and Right 5 Left Right 7 Print pensive Note that the Right function counts from the right side.

413/06/2016 Removing spaces with Trim Trim removes any spaces on the left side and right side of a string. e.g. e.g. EmployeeName = Trim(EmployeeName) txtName.Text = EmployeeName _Mr Lee_ Mr Lee

513/06/2016 Extension Program 1 Rewrite the “Garage” Program to use Left and Right functions instead of the Mid function. “Garage” Program“Garage” Program Note: you must write Microsoft.VisualBasic. Before the function. Note: you must write Microsoft.VisualBasic. Before the function. e.g. Microsoft.VisualBasic.Left Make a copy of the previous program’s whole folder to keep the original program but rename this folder with the same name but add Make a copy of the previous program’s whole folder to keep the original program but rename this folder with the same name but add (Left Right Functions Version) (Left Right Functions Version) See the next slide for some hints. See the next slide for some hints.

Extension Program 1 – “Garage” with Left & Right functions Hints: 1.Look for the colon : using the Instr function to find its position. 2.Use the Left function to extract the numbers before the : as hours. 3.Use the Right function to extract the numbers after the : as minutes. Note that as the Instr function counts from the left side and the Right function counts from the right side, you will need to use the Len function to measure the length of the Duration and then subtract the position of the colon :Note that as the Instr function counts from the left side and the Right function counts from the right side, you will need to use the Len function to measure the length of the Duration and then subtract the position of the colon : Then use this to indicate how many characters to extract from the right, in the Right function.Then use this to indicate how many characters to extract from the right, in the Right function. (LEN(Duration) - (ColonPosition))(LEN(Duration) - (ColonPosition)) Note that as Right is counting from the right side and ColonPosition is given by Instr, which counts from the left side, we do not need to use ColonPosition + 1, just ColonPosition.Note that as Right is counting from the right side and ColonPosition is given by Instr, which counts from the left side, we do not need to use ColonPosition + 1, just ColonPosition. 6 13/06/2016

713/06/2016 Extension Program 2 Trim removes any spaces on the left side and right side of a string. Use Trim in ‘Program 6.1 Validating a Full Name’ to remove any accidental spaces before the surname and after the first name (after each of the two appropriate message boxes). Program 6.1 Validating a Full NameProgram 6.1 Validating a Full Name e.g. change the contents of the text box: e.g. change the contents of the text box: EmployeeName = Trim(EmployeeName) txtName.Text = EmployeeName _Mr Lee_ Mr Lee

813/06/2016 Concatenation Joins strings together using the & operator. e.g. Putting a variable in a message: e.g. Putting a variable in a message: MsgBox (“My name is “ & Name & “. I am “ & Age & “ years old.”) MsgBox (“My name is “ & Name & “. I am “ & Age & “ years old.”) Will show My name is …… I am … years old. This may help you with the next extension program.

913/06/2016 Extension Program 3 – “Concatenation” Gina is developing her programming skills in string handling. She is going to input two strings. Each string is made up of three parts: letters, followed by letters, followed by a single ‘*’ character, followed by a single ‘*’ character, followed by letters letters The groups of letters after the ‘*’ characters are joined together to form a new string which is then output. For example, with “DFG*COM” and “B*PUTER” as inputs, the new string output will be “COMPUTER”. Write the program to perform this task.

Remember – To Search: Use Mid in a loop to extract each character in turn from the beginning to end: For Index = 1 To Len(WordToBeSearched) Character = Mid(WordToBeSearched, Index, 1) If Character = “WhatYouWantToSearchFor” Then Left / Right to extract from the WordToBeSearched e.g. Microsoft.VisualBasic. Left( WordToBeSearched, Index - 1) Microsoft.VisualBasic. Right( WordToBeSearched, Len( WordToBeSearched ) - Index) Or Add the Character extracted to a separate new variable: e.g. NewWord = NewWord & Character ….. End If Next Index This may help you with the next extension programs.

Extension Program 4 – “Remove *” Gina is developing her programming skills in string handling. She is going to input one string. The string contains letters and zero or more '*' characters in any positions. Gina wants to remove all the '*'s and output the letters in their original order. For example: input “com*put**er*”, the output is “computer” input “hardware”, the output is “hardware”

Extension Program 5 – “BIKE IDs” All bikes in stock have a bike ID. Each bike ID is six characters long and has the format BIKEXX, where X is a digit. For example, BIKE65 is a valid bike ID. Write a program that will validate the format of a bike ID input into the variable BikeID and output a suitable message.

1313/06/2016 Plenary What do the Left, Right, LTrim, RTrim, Trim, UCase and LCase functions do? Left returns a substring from the main string starting with the first character up to a specified length. Left returns a substring from the main string starting with the first character up to a specified length. Right returns a substring from the main string starting with last character up to a specified length. Right returns a substring from the main string starting with last character up to a specified length. LTrim removes any leading spaces at the left side of a string. LTrim removes any leading spaces at the left side of a string. RTrim removes any trailing spaces at the right side of a string. RTrim removes any trailing spaces at the right side of a string. Trim does both of the above. Trim does both of the above. UCase converts all characters in a string into their upper case equivalents. LCase vice versa above.