Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Arrays von Arrays (oder falscher Gedanke)

Empfohlene Antworten

Veröffentlicht

Folgendes Problem:

Ich habe in einer Textdatei Informationen gespeichert.

Aufbau der Textdatei:

Kennzeichen1=kennung1,kennung2,kennung3,...

Kennzeichen2=kennung1,kennung2,kennung3,...

Nun möchte ich diese Informationen in ein Array von Arrays (Array1: Zeilenzahl, Array2: Kennungszahl) übertragen, aber ich komme überhaupt nicht weiter.

Im Endeffekt möchte ich gerne ein Aufrufen wie if (Array[1][2] == "ichbineineKennung") ...

Bin ich völlig auf dem falschen Weg?

Wenn nein poste ich natürlich gern das, was ich habe.

Gruß

Kevin

Ich hoffe, es ist nicht allzu lachhaft, aber hier mal der (falsche!) Code:

int linesCountPrüfung = c_textdatei.CountLines(programmDirectory + "set.txt");

            string[] PrüfungString = new string[linesCountPrüfung];

            string[] man;

            for (int r = 1; r <= linesCountPrüfung; r++)

            {

                PrüfungString[(r-1)] = c_textdatei.ReadLine(programmDirectory + "set.txt", r).ToString();

            }

            for (int ab = 0; ab <= linesCountPrüfung; ab++)

            {

                int mei = PrüfungString[ab].Length;

                string[][] PrüfungArrayPrepare = new string[linesCountPrüfung][];

                for (int aa = 0; aa < mei; aa++)

                {

                    PrüfungArrayPrepare[ab][aa] = PrüfungString[aa].Split(new char[] { '=', ',' });

                }

            }

Fehlermeldung:

Eine implizite Konvertierung vom Typ "string[]" in "string" ist nicht möglich.

Ich weiß, dass mir das was sagen soll. Aber ich bekomm den Knoten im Kopf ned auf

Bearbeitet von yamukud
Fehlermeldungsangabe vergessen

String.Split() dürfte ein array liefern, dieses array willst du dann als ein item des PrüfungArrayPrepare arrays speichern.

du müsstest also ein item des von String.Split() gelieferten arrays nehmen statt dem gesamten array.

Wenn du genau hinschaust habe ich sogar genau das gemacht.

Allerdings muss man, wie mir NACH dem Essen (immer wichtig ;) ) aufgefallen ist, das Unterarray zur Laufzeit generieren lassen und das Split an dieses übergeben. Eine Indexierung des Unterarrays ist nicht notwendig.

Für die Googler der richtige Code:

            int linesCountPrüfung = c_textdatei.CountLines(programmDirectory + "set.txt");

            string[] PrüfungString = new string[linesCountPrüfung];

            string[] man;

            for (int r = 1; r <= linesCountPrüfung; r++)

            {

                PrüfungString[(r-1)] = c_textdatei.ReadLine(programmDirectory + "set.txt", r).ToString();

            }

            string[][] PrüfungArrayPrepare = new string[linesCountPrüfung][];

            for (int ab = 0; ab <= linesCountPrüfung; ab++)

            {

                int mei = PrüfungString.Length;

                for (int aa = 0; aa < mei; aa++)

                {

                    PrüfungArrayPrepare[aa] = PrüfungString[aa].Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);

                }

            }

Wenn du genau hinschaust habe ich sogar genau das gemacht.

ähm, nein

du hast

PrüfungArrayPrepare[ab][aa] = PrüfungString[aa].Split(new char[] { '=', ',' });

PrüfungArrayPrepare - typ string[][] PrüfungArrayPrepare[ab] - typ string[] PrüfungArrayPrepare[ab][aa] - typ string Split liefert string[] du hast also versucht einer variablen vom typ string ein string[] zuzuweisen, und das hat der compiler auch bemängelt. eine möglichkeit wäre wenn du nur bestimmte teile des von split erzeugten arrays willst
PrüfungArrayPrepare[ab][aa] = PrüfungString[aa].Split(new char[] { '=', ',' })[iIndex];

beide typen sind string

oder so wie du es jetzt machst das gesamte array von split in das ziel array kopieren, beide typen sind string[]

Entschuldige, natürlich hast du Recht, ich WOLLTE das lediglich machen.

Vielleicht sollte ich erwähnen, dass der Code-Snippet nur ein Versuch war, der auch neben 2-3 anderen stand.

Aber nun ist mir das ganze Klar, ist wie Ableitung und Integration, ist wunderbar.

Danke noch einmal für deine Mühe.

Auch das Beispiel mit dem index hinter ist super, da habe ich noch überlegt, wie das geht und habs über Umwege gemacht.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.