Phyton代码为Cs [英] Phyton code to Cs

查看:94
本文介绍了Phyton代码为Cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将phyton代码转换为Cs。

Hi, I want to convert phyton code to Cs.

这是Phyton代码:

This is the Phyton code:

#open file

myfile = open(" D:\\Users\\xyz\\xyz\\ xyz.log",'r',encoding ='utf-8', errors ='ignore')

#读取所有行

lines = myfile.readlines()

#为文件中的每一行

for line in lines:

    #根据空格分析

    res = line.split('',2)

    date = res [0]

    time = res [1]

   如果"Nao说:"在res [2]中:

       通过

    elif"开始新游戏"在res [2]中:

        #TODO:解析日期和时间,在游戏桌上添加行

       打印("游戏")

# 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")



   否则:

        print(res [2])


    else:
        print(res[2])

xyz.log包含:

The xyz.log contain this:

2018-10-14 12:49:40开始新游戏

2018-10-14 12:49:41 Nao说:好的。

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

2018-10-14 12:50:29寻找类别:3

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

有人可以帮我这个吗?谢谢......

Can someone hel me with this? Thanks...

推荐答案

我做了这个,但我不知道它是否有效,因为我不明白究竟会发生什么事情b

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]);
            }


我刚刚看到了我能理解的东西,我把它变成了"csharpable"。



也许你可以解释一下你到底要做什么。



PS:不要试试这段代码,认为它会100%有效。如果你意识到,"res"在每个指数中没有任何价值,我只是让他的存在成为可能,我没有让他工作,因为他可能应该使用正确的价值。

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.


这篇关于Phyton代码为Cs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆