none
Phyton code to Cs RRS feed

  • Question

  • Hi, I want to convert phyton code to Cs.

    This is the Phyton code:

    # open file
    myfile = open("D:\\Users\\xyz\\xyz\\xyz.log", 'r', encoding='utf-8', errors='ignore')
    # read all lines
    lines = myfile.readlines()
    # for each line in file
    for line in lines:
        # parse based on spaces
        res = line.split(' ', 2)
        date = res[0]
        time = res[1]
        if "Nao says:" in res[2]:
            pass
        elif "Starting new game" in res[2]:
            #TODO: parse date and time, add line to game table
            print("game")

         elif "Looking for category" in res[2]:
            #TODO: save category for question table
            print("category")


        else:
            print(res[2])

    The xyz.log contain this:

    2018-10-14 12:49:40 Starting new game
    2018-10-14 12:49:41 Nao says: OK.

    2018-10-14 12:50:29 Looking for category: 3

    Can someone hel me with this? Thanks...


    • Edited by Ricardito19 Tuesday, February 5, 2019 2:58 PM
    Tuesday, February 5, 2019 2:54 PM

All replies

  • I did this, but I dunno if it works, cause I don't understand exactly what must happen

    var myfile = File.ReadLines("path");
                string[] res = new string[10];
    
                string date = string.Empty;
                string time = string.Empty;
                 
                foreach (var line in myfile)
                {
                    res = line.Split(' ');
                     date = res[0];
                     time = res[1];
                }
                if (res[2]=="Nao says")
                {
                    //pass ...?
                }
                else if (res[2] == "Starting New Game")
                {
                    Console.WriteLine("game");
    
                }
                else if (res[2] == "Looking For Category")
                {
                    Console.WriteLine("category");
                }
                else
                {
                    Console.WriteLine(res[2]);
                }
    I just saw what I could understand, I made it "csharpable".


    Maybe you could explain what are you trying to do exactly.

    PS: don't try this code think that it will 100% work. If u realize, "res" don't have any value in each index, I just made his existence possible, I didn't make him work as he probably should with the right values.


    BP-LP 2005/2016 @ll rights reserved



    Tuesday, February 5, 2019 4:36 PM