Tutorial 11 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Tutorial 11

Description:

Substring Hints. String Processing. String.length gives length of strings aka Len() String.Substring(start, length) gives part of string identified ... Hints: ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 12
Provided by: BenM1
Category:
Tags: hints | tutorial

less

Transcript and Presenter's Notes

Title: Tutorial 11


1
Tutorial 11 12
  • INFS308
  • Spring2006

2
Overview
  • Some String processing functions
  • Select Case Processing

3
Substring Hints
  • String Processing
  • String.length gives length of strings aka Len()
  • String.Substring(start, length) gives part of
    string identified
  • Given textbox1.text has the value Happy
  • textbox1.text.length 5 aka
    Len(textbox1.text)
  • Substring(start, length)
  • Textbox1.text.Substring(0, 1) H
  • Textbox1.text.Substring(2, 3) ppy

4
In Class Exercise
  • Write a program to reverse the contents of a text
    box and place it in a second. Now, determine if
    the contents of the first text box is a
    palindrome. A palindrome is a series of text that
    is the same forwards and backwards. So, madam
    is a palindrome, while happy is not. The string
    madam im adam is also considered a palindrome.
    This means that you must remove the spaces before
    comparing. Finally, Madam Im Adam is also a
    palindrome, which means that you must allow for
    upper case letters.

5
In Class Exercise
6
In Class Exercise
  • You must use a counted loop to go through the
    textboxes.
  • Hints
  • Do the program in steps 1.) reverse the textbox
    1 contents to textbox 2.) check for madam as a
    palindrome 3.) remove the spaces and check for
    madam im adam as a palindrome 4.) now check
    for Madam Im Adam.
  • The Len (string) function returns the length of
    the string
  • The substring method of an object.Text reference
    can be used to obtain a substring from the
    contents of the object.Text.
  • Given that txtIn has the text madam, the
    reference txtIn.Text.Substring(0, 1) evaluates to
    m, the reference txtIn.Text.Substring(2, 1)
    evaluates to d, the reference
    txtIn.Text.Substring(1, 2) evaluates to ad
  • Think about how you would remove the spaces.

7
Case Flowchart
  • Assume that you want to develop a program that
    looks at a coin and adds the value of that coin
    to a total.

Dime ?
Add .10
Penny ?
Add .01
Nickel ?
Add .05
Qtr ?
Add .25
8
If Statement
  • Assume that you want to develop a program that
    looks at a coin and adds the value of that coin
    to a total.
  • IF (coin dime) THEN
  • Total total .10
  • ELSEIF (coin penny) THEN
  • Total Total .01
  • ELSEIF (coin nickel) THEN
  • Total Total .05
  • ELSEIF (coin quarter) THEN
  • Total Total .25
  • ENDIF

9
Case Flowchart
  • Select Case coin
  • Case dime
  • total total 10
  • Case penny
  • total total 1
  • Case nickel
  • total total 5
  • Case quarter
  • total total 25
  • Case Else
  • total total 0
  • End Select

Dime ?
Add .10
Penny ?
Add .01
Nickel ?
Add .05
Qtr ?
Add .25
10
Select Case Statement
  • Special If statement with ElseIf
  • Evaluates expression then looks for case matching
    expression
  • If found, it executes first case that matches and
    ends Select Case statement
  • Format
  • Select Case expression
  • Case expressionlist1
  • block1
  • Case expressionlist2
  • block2
  • Case expressionlistN
  • blockN
  • Case Else
  • Else block
  • End Select

11
Summary
  • Strings can be processed like listboxes they are
    a structure with each letter or character as an
    element.
  • Select Case
  • Substitutes for IF THEN ELSEIF construct
  • Executes first condition that is true and exits
    to END SELECT
Write a Comment
User Comments (0)
About PowerShow.com