### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [solved] How to check if an Integer is a control-character?  (Read 309 times)

#### Zvoni

• Sr. Member
• Posts: 429
##### [solved] How to check if an Integer is a control-character?
« 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 ?
« Last Edit: October 24, 2020, 12:19:39 pm by Zvoni »
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft

#### Bart

• Hero Member
• Posts: 4096
##### Re: How to check if an Integer is a control-character?
« Reply #1 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

#### Bart

• Hero Member
• Posts: 4096
##### Re: How to check if an Integer is a control-character?
« Reply #2 on: October 24, 2020, 12:04:49 pm »

#### Zvoni

• Sr. Member
• Posts: 429
##### Re: How to check if an Integer is a control-character?
« Reply #3 on: October 24, 2020, 12:17:43 pm »
Thx Bart, so i was close with my second guess
One System to rule them all, One IDE to find them,
One Code to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
People call me crazy, because i'm jumping out of perfectly fine aircraft