String Processing - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

String Processing

Description:

MyString = 'This has numbers 1234 and text!' Concatenation. We have seen how we can concatenate smaller strings to form larger strings... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 10
Provided by: matt131
Category:

less

Transcript and Presenter's Notes

Title: String Processing


1
String Processing
  • We have established that a string variable may be
    used to store alphanumeric data, e.g.
  • Dim MyString as String
  • MyString "This has numbers 1234 and text!"

2
Concatenation
  • We have seen how we can concatenate smaller
    strings to form larger strings
  • Dim Var1 as String
  • Dim Var2 as String
  • Dim Var3 as String
  • Var1 "Hello"
  • Var2 "World"
  • Var3 Var1 " " Var2
  • Resulting in Var3 containing "Hello World".

3
  • Two new things we are going to look at today are
    are
  • Splitting Strings
  • Padding Strings

4
How are Strings Split?
  • To split a string, we use a method of a string
    variable called SubString.
  • E.g.
  • StringName.SubString(Start, Length)

5
SubString Version 1
  • The following code splits a string at a start
    position returning a specified number of
    characters
  • Dim String1 as String
  • Dim String2 as String
  • String1 "Hello World"
  • String2 String1.SubString(6,5)
  • At the end of this code String2 would contain
    the text "World".

6
Questions
  • Given the following text
  • Hello World
  • what sub strings are returned by the following
  • SubString(0,5)
  • SubString(1,1)
  • SubString(11,5)
  • What substring code would need to be written to
    extract the text "Hell" from the above string?

7
SubString version 2
  • Essentially what this does is tell VB to return
    the right hand part of a string from a specified
    position, so
  • Dim String1 as String
  • Dim String2 as String
  • String1 "Hello World"
  • String2 String1.SubString(6)
  • Would start at position 6 "W" and return the rest
    of the string "World".

8
Padding Strings
  • PadRight
  • PadRight in it's simplest form accepts one
    parameter which specifies how large the string
    should be "padded" to.
  • For example
  • The text "hello" padded right 10 would produce
  • "hello "

9
  • What do you suppose the following code does?
  • Dim String1 as String
  • Dim String2 as String
  • String1 "hello"
  • String2 String1.PadRight(20,"")
  • What happens with the following code?
  • Dim String1 as String
  • Dim String2 as String
  • String1 "hello"
  • String2 String1.PadRight(2)
Write a Comment
User Comments (0)
About PowerShow.com