Entwickler-Ecke

C# - Die Sprache - Semikolons zählen !!


Matti - Mo 16.10.06 16:36
Titel: Semikolons zählen !!
Hi,

ich will in einem String die Anzahl der Semikolons zählen und in net Int16 Variable schreiben ...

Ich habe allerdings keine Ahnung wie ich die durchführen kann ... Bitte helft mir !!

mfg, Matti


gozza01 - Mo 16.10.06 17:39
Titel: So in etwa

C#-Quelltext
1:
2:
3:
string strQuelle = "1;2;3;4;5";
string[] split = strQuelle.Split(';');
Int16 iAnzahl = (Int16)(split.Length - 1);


Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt


Christian S. - Mo 16.10.06 17:54

Wieso ein Array anlegen, um zu erfahren, wieviel Semikolon drin vorkommen? :gruebel:

Eher so:

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
string strQuelle = "1;2;3;4;5";
int count = 0;
int position = -1;
do {
  position = strQuelle.IndexOf(";", position+1);
  if (position > -1)
    count++;
while (position <> -1)


Ist ungetestet, sollte aber so laufen.