我想在每個單獨的行使用String.Split方法拆分我的字符串列表,但下面的方法和正則表達式方法都不起作用。相反,他們返回了以下結果{0} 0. System.String[]
而不是實際的字符串數組。請幫忙找到下面的代碼中的錯誤:C#:使用String.Split方法拆分每個單獨的行的字符串列表?
string m_settings_temp;
string[] m_settings;
public void ShowSettingsGui() {
var dialog = new OpenFileDialog { Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*" };
if (dialog.ShowDialog() != DialogResult.OK) return;
m_settings_temp = File.ReadAllText(dialog.FileName);
m_settings = m_settings_temp.Split(new [] { '\r', '\n' });
//This regex method failed as well:
//m_settings = Regex.Split(m_settings_temp,"\r\n|\r|\n");
}
//The method below is to evaluate the output
protected override void SolveInstance(IGH_DataAccess DA)
{
if (m_settings == null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You must declare some valid settings");
return;
}
DA.SetData(0, m_settings);
}
在此先感謝!
該方法返回一個字符串數組 - 而不是一個字符串。 – Oded 2012-08-13 10:28:49
您選擇閱讀多少個文件? – 2012-08-13 10:32:30
@ user861114只有一個。 – 2012-08-13 11:19:23