I am trying to split my list of strings at each separate lines using the String.Split method but the both the method below and a regex method did not work. Instead, they returned the following result {0} instead of the actual array of strings. Please help to find the error(s) in the code below:
0. System.String[]
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);
}
Thanks in advance!
just use
ReadAllLineslike thisthis will give you a
string[]with an element for each line in the selected file. If, after running this code,m_settingshas no elements, the file you selected was empty.If I wanted to interrgoate the contents of
m_settingsin a console app I might do somthing like.This would output the content of array, one element at a time. If I used the implementation of
ToStringfor am array, like this,I would get a string representation of the array’s type and the number of elements it contains.
I suspect in your case you want to do somthing like