Recent

Author Topic: (Solved)Trouble with syntax  (Read 896 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
(Solved)Trouble with syntax
« on: January 28, 2021, 07:34:38 pm »
 I want to check that the first character in a string is 'A'..'Z', 'a'..'z' but I get an error:
unit2.pas(596,17) Error: Operator is not overloaded: not "ShortString"

Code: Pascal  [Select][+][-]
  1.  Var  First : ShortString; = 'Just a String';
  2.  
  3.    if not First in (['A'..'Z', 'a'..'z']) then  begin
  4.       Result := False;
  5.       X := 2;
  6.       exit;
  7.    end;

Thanks
« Last Edit: January 28, 2021, 08:52:29 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Paolo

  • Hero Member
  • *****
  • Posts: 510
Re: Trouble with syntax
« Reply #1 on: January 28, 2021, 07:46:37 pm »
If I understood you have to do something like
Code: Pascal  [Select][+][-]
  1.  Var  First : ShortString; = 'Just a String';
  2.  
  3.    if not First[n] in (['A'..'Z', 'a'..'z']) then  begin
  4.       Result := False;
  5.       X := 2;
  6.       exit;
  7.    end;
  8.  

Where n is the index of character position in the string First. In your case n=1
« Last Edit: January 28, 2021, 07:49:21 pm by Paolo »

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Trouble with syntax
« Reply #2 on: January 28, 2021, 07:51:19 pm »
Yea, I see it. Thanks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Trouble with syntax
« Reply #3 on: January 28, 2021, 08:00:11 pm »

Changed the line and now I get a type mismatch error


Code: Pascal  [Select][+][-]
  1.   Var First : ShortString = 'Just a string';
  2.  
  3.    if not First[1] in ['A'..'Z', 'a'..'z'] then  begin Result := False; X := 2; exit; end;
  4.  
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Trouble with syntax
« Reply #4 on: January 28, 2021, 08:02:11 pm »

Changed the line and now I get a type mismatch error

Which reads like... ?

Try

Code: Pascal  [Select][+][-]
  1.   Var First : ShortString = 'Just a string';
  2.  
  3.    if not (First[1] in ['A'..'Z', 'a'..'z']) then  begin Result := False; X := 2; exit; end;
  4.  

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Trouble with syntax
« Reply #5 on: January 28, 2021, 08:07:46 pm »
Yea, That compiles. I think I'm good.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

marcio2003

  • Jr. Member
  • **
  • Posts: 69
Re: (Solved)Trouble with syntax
« Reply #6 on: January 28, 2021, 09:09:38 pm »
To complete, perform tests with empty string and UTF8 char string.
Lazarus 2.0.10 Windows 10 64bits

 

TinyPortal © 2005-2018