string valeur = ligne.Split(ChrW(59))(0);
what is the equivalent of that in C# please???

Recommended Answers

All 14 Replies

string valeur = ligne.Split(ChrW(59))(0);

Can you explain this method? What it Does?

this methode is for the read of csv file,and i don´t really what it do,i never use VB that ist way i am asking

What is "ligne"?? Is it a string?

yes it is

"ChrW"?? This one??

If ligne is a string how could it read from a CSV. It will be usefull if give the sample coding in which ligne,ChrW are related.. Me too don't know VB. I need to make a try?

That is a piece of this code, just look about it,may be it will be better for you.

423.  private void load_courbes()
424.  {
425.    bool dateLu = false;
426.    XDate axeX;
427.    // ouvre la boite de choix de fichier
428.    OpenFileDialog open_csv = new OpenFileDialog();
429.    open_csv.Filter = "Fichiers de données|*.csv";
430.    open_csv.Title = "Selectionner le fichier à visualiser";
431.    open_csv.ShowDialog();
432.    // récupére le nom et le chemin choisi
433.    if (open_csv.FileName.ToString != "")
434.    {
435.      string FichierALire = open_csv.FileName;
436.      if (System.IO.File.Exists(FichierALire))
437.      {
438.        // on vide les anciens points et on décoche les combos
439.        initform();
440.        try {
441.          StreamReader sr = new StreamReader(FichierALire, System.Text.Encoding.Default);
442.          string ligne = sr.ReadLine();
443.          //(s'en servir pour nommer directement le nom des courbes, plus souple pour le futur)
444.          //--- Traitement du fichier de données ligne par ligne ---
445.          while (!sr.EndOfStream()) {
446.            ligne = sr.ReadLine();
447.            string valeur = ligne.Split(ChrW(59))(0);
448.            System.DateTime x1 = (System.DateTime)valeur;
449.            axeX = x1.ToOADate();
450.            // archive la premiére date lu pour démarrer l'axe X
451.            if (!dateLu)
452.            {
453.              minX = axeX;
454.              dateLu = true;
455.            }
456.
457.            // enregistre les autres points dans les courbes
458.            // poids de la mousse
459.            valeur = ligne.Split(ChrW(59))(1);
460.            if (valeur != "") P1.Add(axeX, (double)valeur); 
461.            // t mousse
462.            valeur = ligne.Split(ChrW(59))(2);
463.            if (valeur != "") T1.Add(axeX, (double)valeur); 
464.            // hr mousse
465.            valeur = ligne.Split(ChrW(59))(3);
466.            if (valeur != "") HR1.Add(axeX, (double)valeur); 
467.            // t four
468.            valeur = ligne.Split(ChrW(59))(4);
469.            if (valeur != "") T2.Add(axeX, (double)valeur); 
470.            // hr four
471.            valeur = ligne.Split(ChrW(59))(5);
472.            if (valeur != "") HR2.Add(axeX, (double)valeur); 
473.            // v four
474.            valeur = ligne.Split(ChrW(59))(6);
475.            if (valeur != "") V1.Add(axeX, (double)valeur); 
476.            //t ext
477.            valeur = ligne.Split(ChrW(59))(7);
478.            if (valeur != "") T3.Add(axeX, (double)valeur); 
479.            // hr ext
480.            valeur = ligne.Split(ChrW(59))(8);
481.            if (valeur != "") HR3.Add(axeX, (double)valeur); 
482.            // p ext
483.            valeur = ligne.Split(ChrW(59))(9);
484.            if (valeur != "") P2.Add(axeX, (double)valeur); 
485.            // p four
486.            valeur = ligne.Split(ChrW(59))(10);
487.            if (valeur != "") P3.Add(axeX, (double)valeur); 
488.            // E1 ouverture porte
489.            valeur = ligne.Split(ChrW(59))(11);
490.            if ((bool)valeur)
491.            {
492.              EV1.Add(axeX, 5);
493.            }
494.            else
495.            {
496.              EV1.Add(axeX, 0);
497.            }
498.            // E2 phase une 
499.            valeur = ligne.Split(ChrW(59))(12);
500.            if ((bool)valeur)
501.            {
502.              EV2.Add(axeX, 10);
503.            }
504.            else
505.            {
506.              EV2.Add(axeX, 0);
507.            }
508.            // E3 phase deux 
509.            valeur = ligne.Split(ChrW(59))(13);
510.            if ((bool)valeur)
511.            {
512.              EV3.Add(axeX, 15);
513.            }
514.            else
515.            {
516.              EV3.Add(axeX, 0);
517.            }
518.            // E4 phase trois
519.            valeur = ligne.Split(ChrW(59))(14);
520.            if ((bool)valeur)
521.            {
522.              EV4.Add(axeX, 20);
523.            }
524.            else
525.            {
526.              EV4.Add(axeX, 0);
527.            }
528.            // E5 reserve
529.            valeur = ligne.Split(ChrW(59))(15);
530.            if ((bool)valeur)
531.            {
532.              EV5.Add(axeX, 25);
533.            }
534.            else
535.            {
536.              EV5.Add(axeX, 0);
537.            }
538.
539.
540.          }
541.          //--- Referme StreamReader
542.          sr.Close();
543.          // archive la derniére date lu pour echelle au plus juste
544.          maxX = axeX;
545.        }
546.        catch (Exception ex) {
547.          //Traitement de l'exception sinon : 
548.          // Throw ex
549.          MsgBox("Impossible de lire le fichier de données !" + vbCrLf + "fichier " + FichierALire + vbCrLf + "  incompatible ! selectionner un autre fichier.", MsgBoxStyle.Critical, "erreur critique");
550.          // on vide les points qui ont été récupérés avant l'erreur
551.          //  et on décoche les combos
552.          initform();
553.
554.          // on quit
555.          return; // TODO: might not be correct. Was : Exit Sub
556.        }
557.      }

Its taking a string called ligne, splitting it at char 59 (that's a semicolon), and assigning valeur as index zero of the split.

C# equivalent of that

string valeur = ligne.Split(';')[0];
commented: Good one. +4

Erm..that code above is already in C#.

yes that was my problem, ChrW is not a C# Methode C#

Hi WildBamaBoy
Does ChrW(59) indicates ";", and how?

The ChrW() function "returns a character associated with the specified character code."

Here's a list of character codes. DEC 59 is a ';'. :)

EDIT: I am sorry, I've never even heard of ZedGraph.

Thanx Wildboy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.