C# 编辑具有特定索引的列表时,会打印额外代码
我正在创建一个简单的C#程序,它可以自动编辑特定PHP文件的不同部分(用于我的工作)。但我有个问题。我正在处理多个PHP文件,都在不同的子文件夹中,但布局相同 该程序可以访问所有文件夹,并一次编辑所有文件。它将每个文件的内容存储在C# 编辑具有特定索引的列表时,会打印额外代码,c#,php,.net,C#,Php,.net,我正在创建一个简单的C#程序,它可以自动编辑特定PHP文件的不同部分(用于我的工作)。但我有个问题。我正在处理多个PHP文件,都在不同的子文件夹中,但布局相同 该程序可以访问所有文件夹,并一次编辑所有文件。它将每个文件的内容存储在列表中。该程序的主要目的是更新每个文件中的单个字符串,然后保存该文件。完成此操作后,我希望Console打印出每个文件中的单个更新字符串,以及文件的路径。以下是该计划的具体部分: foreach(路径中的字符串项) { if(File.Exists(item)==fal
列表中。该程序的主要目的是更新每个文件中的单个字符串,然后保存该文件。完成此操作后,我希望Console
打印出每个文件中的单个更新字符串,以及文件的路径。以下是该计划的具体部分:
foreach(路径中的字符串项)
{
if(File.Exists(item)==false)//检查文件是否存在
{
控制台。WriteLine(“错误!”);
Console.WriteLine(“未找到名为“+Path.GetFileName(item)+”的文件”);
WriteLine(“请确认您选择了正确的文件。”);
}
其他的
{
List filecontents=File.ReadAllLines(item.ToList();
for(int i=0;i
这段代码起初对我来说很好,直到我看到结果:
$real\u home=”http://test123/uadmin/gate.php";
位于(父文件夹的路径)
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]$real\u home=”http://test123/uadmin/gate.php";
位于(父文件夹的路径)
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]$real\u home=”http://test123/uadmin/gate.php";
位于(父文件夹的路径)
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]$real\u home=”http://test123/uadmin/gate.php";
在父文件夹的*路径找到*
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]$real\u home=”http://test123/uadmin/gate.php";
位于(父文件夹的路径)
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]$real\u home=”http://test123/uadmin/gate.php";
位于(父文件夹的路径)
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]$real\u home=”http://test123/uadmin/gate.php";
位于(父文件夹的路径)
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]$real\u home=”http://test123/uadmin/gate.php";
位于(父文件夹的路径)
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]
这个程序在这里工作,因为我把“test123”作为变量domainname
。当然,这个字符串:
System.Collections.Generic.List`1[System.String]System.Collections.Generic.List`1[System.String]
不属于那里
现在,我的问题是。这是否仅当我从filecontents
打印出特定字符串时才发生?或者它也像那样存储在列表中?还有,有人知道为什么会发生这种情况,以及如何消除它吗
注意:在打印之前将列表转换为数组也没有帮助。这意味着它是一个列表
,您需要在它上面循环,有没有可能为虚拟PHP文件提供一个示例?如果您对列表
类型对象或类似对象调用ToString()
,通常会发生这种情况。您是否检查了tempsubstring
变量以查看该类型字符串是否在其中运行?文件内容,你自己核实过吗?