Idiomatically determine all the characters that can be used for symbols: Difference between revisions

no edit summary
(Added FreeBasic)
No edit summary
Line 57:
2nd..nth char: 193 bad, 63 ok: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
This code test the all printable ASCII characters to see if they are valid in symbols. It uses the the Delphi system call "IsValidIdent" to determine what the compiler will accept. It starts by testing single characters identifiers, which tests the first character of the identifier. Then tests the second character. This tells which characters are valid for the rest of an identifier.
 
<syntaxhighlight lang="Delphi">
 
 
procedure ShowValidSymbols(Memo: TMemo);
{Uses Delphi system tool "IsValidIndent" }
{To identify valid characters in indentifiers}
var I: integer;
var TS: string;
var Good,Bad: string;
begin
{Test first characters in a symbol}
Good:=''; Bad:='';
for I:=$21 to $7F do
begin
TS:=Char(I);
if IsValidIdent(TS) then Good:=Good+TS
else Bad:=Bad+TS;
end;
Memo.Lines.Add('First Characters Allowed');
Memo.Lines.Add('Allowed: '+Good);
Memo.Lines.Add('Not Allowed: '+Bad);
{Test remaining characters in a symbol}
Good:=''; Bad:='';
for I:=$21 to $7F do
begin
TS:='A'+Char(I);
if IsValidIdent(TS) then Good:=Good+TS[2]
else Bad:=Bad+TS[2];
end;
Memo.Lines.Add('');
Memo.Lines.Add('Remaining Characters Allowed');
Memo.Lines.Add('Allowed: '+Good);
Memo.Lines.Add('Not Allowed: '+Bad);
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
First Characters Allowed
Allowed: ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
Not Allowed: !"#$%&'()*+,-./0123456789:;<=>?@[\]^`{|}~
 
Remaining Characters Allowed
Allowed: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
Not Allowed: !"#$%&'()*+,-./:;<=>?@[\]^`{|}~
 
Elapsed Time: 9.048 ms.
 
</pre>
 
 
=={{header|F_Sharp|F#}}==
465

edits