Pascal Programming - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Pascal Programming

Description:

... program a string is a variable length sequence of alpha-numeric characters. It can be used to store data typed in by a user or to present formatted data ... – PowerPoint PPT presentation

Number of Views:163
Avg rating:3.0/5.0
Slides: 12
Provided by: website6
Category:

less

Transcript and Presenter's Notes

Title: Pascal Programming


1
Pascal Programming
  • Strings String Functions
  • National Certificate Unit 4
  • Carl Smith

2
What is a string?
  • In a computer program a string is a variable
    length sequence of alpha-numeric characters.
  • It can be used to store data typed in by a user
    or to present formatted data (information) to the
    user e.g.
  • writeln(fred10)

3
Joining strings
  • Strings often need to be concatenated or joined
    to make a further string
  • In Pascal, this can be done in two ways-
  • concat(string1.stringn)
  • OR
  • string3 string1 string2

4
String Functions
  • length
  • returns the length of a string
  • writeln (length of string ,length(fred))

5
Inserting strings
  • insert
  • inserts a string into another string at a fixed
    point
  • insert(added, fred, 5)
  • inserts the word added starting at 5th
    character of string fred

6
Copy Function
  • Copysometimes called (in VB for example) the
    substring, left or right
  • It allows you to select part of an existing
    string e.g.
  • fred Hello out there
  • fred2 copy(fred, 7, 3)
  • would make fred2 equal out

7
Pos function
  • Pos (sometimes called the index)
  • returns the START position of a substring within
    a string
  • fred Hello out there
  • writeln(Position is ,pos(the,fred))
  • returns the value of 11(NOTE a space is still a
    character)

8
Delete Function
  • Delete
  • deletes a substring from a string
  • fred Hello you out there
  • delete(fred, 7 , 4)
  • will delete you (including the space) from the
    string variable fred

9
Processing Strings
  • We have the ability to address any character
    within a string
  • remember that we can define a string with a
    maximum number of characters e.g.-
  • fred string20
  • fred1(fred1)fred1 contains 1st char
  • fred2(fred2)fred2 contains the 2nd char
    etc
  • NOTE that string fred is NOT an array, we are
    just accessing each one of the characters within
    the string using this technique.

10
Numbers and Strings
  • Sometimes we need to convert a number stored in a
    string to an integer or real or vice versa
  • Pascal provides the inbuilt STR and VAL
    procedures to allow this
  • Val(ltstringgt,ltnumbergt,ltcodegt)ltnumbergt string
    converted to a number
  • Str(ltnumbergt,ltstringgt)ltstringgt number
    converted to a string

11
Summary
  • In this lecture we-
  • Identified what a string is in a computer
    program
  • Explored the functions that PASCAL provides to
    manipulate strings
  • Looked at how to process strings
Write a Comment
User Comments (0)
About PowerShow.com