In C#
var parameters =
from line in parameterTextBox.Lines
select new {name = line.Split(' ').First(), value = line.Split(' ').Skip(1)};
Is there a way to do this without having to split twice?
In C#
var parameters =
from line in parameterTextBox.Lines
select new {name = line.Split(' ').First(), value = line.Split(' ').Skip(1)};
Is there a way to do this without having to split twice?
you can store the split in a let
clause
var parameters =
from line in parameterTextBox.Lines
let split = line.Split(' ')
select new {name = split.First(), value = split.Skip(1)};
Sure.
var parameters = from line in parameterTextBox.Lines
let words = line.Split(' ')
select new { name = words.First(), words.skip(1) };
You might try this:
private Dictionary<string, string>getParameters(string[] lines)
{
Dictionary<string, string> results = new Dictionary<string, string>
foreach(string line in lines)
{
string pName = line.Substring(0, line.IndexOf(' ');
string pVal = line.Subsgring(line.IndexOf(' ') + 1);
results.Add(pName, pVal);
}
return results;
}
string Str= "one all of the rest";
Match m = Regex.match(Str,"(\w*) (\w.*)");
string wordone = m.Groups[1];
string wordtwo = m.Groups[2];