Pascal Exam help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Pascal Exam help

SoilahSoilah Posts: 1Member
Hi there, it seems that I like alot of other posters have found myself in a bit of a situation, i have a programming exam on Monday and we have been given the single worst bit of code I have ever seen in my life, im sure most of the others doing this exam know what i mean, and to make matter worse some idiot at school accidently deleted string.tpu and we have no back up so we're all using a totally new version of pascal that we don't fully understand.

Now to the problem, i was wondering if anyone can tell me how to check through a sting to see if there is a intger or punctuation in the string.

we are using Turbo Pascal for windows and using wincrt and strings "uses" thingy.

anyone else using a Turbo pascal for windows i have worked out a way to convert from lower case to upper case.

Begin
Repeat
Write('Key in new phrase ...(letters and any Spaces) ');

readln(s);
for i:= 1 to length(s) do
s[i]:=upcase(s[i]);
ThisNewPhrase := s

make sure u add variable
i :integer;
s :string;

Comments

  • Phat NatPhat Nat Posts: 757Member
    You should put this into a function called UpperCase() or ToUpper(), etc. Then you can use it anywhere in your code without having to retype it all the time
    [code]
    for i:= 1 to length(s) do
    s[i]:=upcase(s[i]);
    [/code]

    [code]
    FUNCTION UpperCase( s : String) : String;
    VAR
    i : Byte;
    Begin
    for i:= 1 to length(s) do
    s[i]:=upcase(s[i]);
    UpperCase := s;
    End;
    [/code]

    Also, for finding a persiod in a string you can use Pos()
    [code]
    Bsgin
    s := 'Hello.World!';
    WriteLn('period is at position ',Pos('.', s));
    End.
    [/code]
    For finding an integer, search through the string for a digit, then find out how many digits are in a row. Copy these digits into a new string and use Val() to convert them. I don't have much time right now, so you do the first part and the end will look like this:

    [code]
    VAR
    s : String;
    Number,
    Error : Integer;
    {...}
    s := '321';
    Val(s, Number, Error);
    { Error will be 0 if the string is a number }
    [/code]
Sign In or Register to comment.