# Lazarus

## Free Pascal => General => Topic started by: Zvoni on October 24, 2020, 11:21:00 am

Title: [solved] How to check if an Integer is a control-character?
Post by: Zvoni on October 24, 2020, 11:21:00 am
Hi Folks,

still translating c-code.

How do i check if a Integer is a control-character?
Code: C  [Select][+][-]
1. int MyFunction(int c)
2. {
3.     return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' ||  c == '\v';
4. }
5.
Code: Pascal  [Select][+][-]
1. Function MyFunction(c:Integer):Boolean
2. Begin
3.   Result:=(c=Ord(' ')) Or //???????
4. End;
5.
For the life of me i can't find anyting for this.

And yes, i'm aware that i'm checking if c is a whitespace-character
And, no. I'm using {H+} so IsWhiteSpace-Function is not option.

EDIT: After reading up on it: Or is it enough to check if #32 and everything <= #13 ?
Title: Re: How to check if an Integer is a control-character?
Post by: Bart on October 24, 2020, 11:35:51 am
Basically you want to detect CarriageReturn, LineFeed, FormFeed, Space, Tab and VerticalTab.

Integer values:
CarriageReturn = 13
LineFeed = 10
FormFeed = 12
VertcalTab = 11
Tab = 9
Space = 32

Code: Pascal  [Select][+][-]
1. function MyFunction(C: Integer): Boolean;
2. begin
3.   Result := (C in [9,11,12,13,32]);
4. end;

Or

Code: Pascal  [Select][+][-]
1. function MyFunction(C: Char): Boolean;
2. begin
3.   Result := (C in [#9,#11,#12,#13,#32]);
4. end;

Bart
Title: Re: How to check if an Integer is a control-character?
Post by: Bart on October 24, 2020, 12:04:49 pm