本文介绍了从处理文件中读取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个程序.
第一个有一个列表框和一个按钮.
第二个只有一个列表框.
第一个程序将列表框的项目保存为.abc文件中的字符串.
我已将第二个程序与.abc文件相关联,因此,当我双击.abc文件时,它将与第二个程序一起打开.
如何使打开我的.abc文件时,我的第二个程序读取保存在.abc文件中的字符串项目,并将它们作为变量放入列表框中.

I have 2 programs.
The first has 1 listbox and a button.
The second has just a listbox.
The first program saves the listbox''s items as string in an .abc file.
I''ve associated my second program with .abc files so when i double click an .abc file, it opens with my second program.
How to make so that when i open an .abc my second program reads the string items that are saved into the .abc file and put them as a variable into the listbox.

推荐答案

string[] args = Environment.GetCommandLineArgs();

,您将收到文件名.



"它表示字符串是类类型,不能用作表达式.
我需要将文件中的项目作为字符串使用,以将它们与变量一起使用.
能给我一个示例代码吗,请问我真的是编程新手!! :)谢谢!"


in the load event of your main form, you will receive the file name.



"it says string is a class type and cannot be used as an expression.
i need the items that are into the file as string to use them with a variable.
can you give me a sample code please I am really new in programming PLEASE!! :) thanks!"


string[] args = Environment.GetCommandLineArgs();
foreach (string filename in args)
    {
    if (File.Exists(filename))
        {
        // Pick one of these as appropriate for your app.
        string text = File.ReadAllText(filename);
        string[] textAsLines = File.ReadAllLines(filename);
        // Handle the file content
        ...
        }
    }



这篇关于从处理文件中读取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 13:19
查看更多