Autor Beitrag
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 20.09.05 11:17 
Hi!

In Delphi kann ich z.B. folgende Abfrage machen:
ausblenden Delphi-Quelltext
1:
if not aChar in ['0'..'9',keys.KeyBack,'.',','then					


Wie geht das in C#?

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Di 20.09.05 12:10 
Hallo,

Mengen waren ja schon immer eine Pascal spezialität, welche kaum eine andere Programmiersprache beherscht. Ich kann es bei C# nicht 100%ig sagen, da ich aber nirgens einen gegenteiligen hinweis gefunden habe, gehe ich davon aus, dass auch diese Sprache keine Mengen beherrscht.

Das bedeutet für dich, dass du die bedingung umformulieren musst:

ausblenden C#-Quelltext
1:
2:
 if (!(((aChar >= '0') && (aChar <= '9')) || (aChar == keys.KeyBAck) || (aChar == '.') || (aChar ==',')) 
{ ...

Ich hoffe ich bin dabei nciht durcheinander gekommen.

Gruß
Klabautermann
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 20.09.05 12:28 
Das Problem hatte ich auch mal und wenn ich mich recht erinnere warst sogar du derjenige, der mir den Tipp mit der Regular Expression gegeben hat.. ;)
ausblenden C#-Quelltext
1:
if (!(new Regex('[0-9\b]', RegexOptions.IgnoreCase).IsMatch(<char>)) ...					

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Christian S. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 20.09.05 12:44 
Ja, schon richtig. Aber findest Du die Lösung
( ) elegant
( ) performant
( ) befriedigend
?

Zutreffendes bitte ankreuzen :D

Und da ich das jetzt auch wieder brauche, wollte ich doch gleich mal diese Sparte testen ;-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 20.09.05 12:45 
user profile iconChristian S. hat folgendes geschrieben:
(X) elegant
(zumindest performant genug) performant
(X) befriedigend

;)

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Robert_G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416


Delphi32 (D2005 PE); Chrome/C# (VS2003 E/A, VS2005)
BeitragVerfasst: Di 27.09.05 19:42 
Ich hätte es wohl so gelöst:
ausblenden C#-Quelltext
1:
2:
3:
4:
return !(char.IsNumber(someChar) || 
         someChar == (char)Keys.Back ||
         someChar == '.' ||
         someChar == ',' );

Was macht der Chrome compiler aus dem Code?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
class method ConsoleApp.EvilChar(someChar : Char) : Boolean; 
begin
  exit (someChar not in ['0'..'9'
                         Char(Integer(Keys.Back)),
                         '.'',']);
end;

Nicht hübsch, aber selten. :P
ausblenden C#-Quelltext
1:
2:
3:
4:
public static bool EvilChar(char someChar)
{
  return !(((((someChar >= '0') & (someChar <= '9')) | (someChar == '\b')) | (someChar == '.')) | (someChar == ','));
}


Es gibt auch einen netten Artikel über Sets in C# im allwissenden MSDN. ;) Efficiently Representing Sets
Christian S. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 27.09.05 19:53 
Hallo!

Ich habe den Artikel im MSDN bisher nur überflogen (wieso müssen die Code immer so klein schreiben?), werde mir das mal heute abend zu Gemüte führen. Ich schätze aber mal, dass das performanter als ein regulärer Ausdruck sein dürfte ;-)

Auf jeden Fall schon mal vielen Dank!

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".