It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I cant figure out howto split items from my genericList to two seperate parts with delimiter option?
List<string> fileLines = File.ReadAllLines(fileName).Skip(4).ToList();
foreach (var item in fileLines)
{
values = item.Split(' ');
sList.Add(values[3].Substring(2).Trim());
}
My sList looks like this:
10.5 5.5
7.2 2.5
-0.1 3.0
-1.1 3.3
and so on .......... totaly 8760 rows in my List.
What I want to do is to split each row from the List to two seperate parts so I can count the min, max and average on thoose values.
(each value is meant to represent the temperature, so double)
Any help would be appreciated !!! Thanx
So why don't you use this one
List<string> fileLines = File.ReadAllLines(fileName).Skip(4).ToList();
foreach (var item in fileLines)
{
values = item.Split(' ');
string[] vl=values[3].Substring(2).Trim().Split('\t');
sList1.Add(vl[0]);
sList2.Add(vl[1]);
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am building a list from a dataset as 12345_9876,125675_0987,
I try to remove the last , from the list like we do for strings..
value.TrimEnd(',');
Can we do similar thing for a list?
I hope this will help you?
var lastElement = yourList.ElementAt<string>(yourList.Count - 1).TrimEnd(',');
yourList.RemoveAt(yourList.Count - 1);
yourList.Insert(yourList.Count,lastElement);
Think you just want this?:
List<string mylistfromdataset = // I dunno how you populated it
var newlist = mylistfromdataset.Select(x=> x.TrimEnd(',')).ToList();
EDIT after the poster cleared the question, you could use this 2 line code to make a new list where the last string the , is trimmed.
var list = listofstring.Take(listofstring.Count - 1).ToList();
list.Add(listofstring.Last().TrimEnd(','));
(Make a list excluding the last item. then trim the last item with , at the end and at it to the new list.)
Just use String.Join:
String delimitedList = String.Join(",", yourList);
int i=value.LastIndexOf(",");
if(i!=-1)
value=value.Remove(i,1);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have an array of object called objStud within it has another array
how do I loop and display them?
Here is an image that you can see how objStud is like
Just use nested foreach statements
foreach (Student stud in objStud)
{
foreach (Fee in stud.Fees)
{
// Do something with stud and/or fee
}
}
You can use SelectMany to flatten first:
foreach(var fee in objStud.SelectMany(x => x.Fees))
{
}
You can use "foreach" in looping and displaying the values. This is a very easy and good example on how to access the data that you want to display.
This will also teach you the concept behind array. Have fun!
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am new at C#.net. Could somebody help me with the following issue? Thank you.
I need to read the content from a file, then check each row of the file for data that are separated by ":" or ",". Then get the data that is between ":" and ",". Finally add it to the datatable.
How do I do this?
Any help is highly appreciated.
String linestring = streamreader.ReadLine();
String[] linetokens = linestring.Split(new String[]{":",","}, StringSplitOptions.None);
After that linetokens array will be filled with the segments you need.
Given the generality and overall scope of your question (ie, you should break it up into the parts you don't understand and ask them individually), this is best I could come up with that could do what you want.
var data = File.ReadLines() // read the content from a file
.Where(line => line.Contains(":") && line.Contains(",") // data separated by ":" & ","
.Select(line => line.Split(":,".ToArray())[1]) // data between ":" & "," -- could yield data between "," and ":"
.Select(data => new object[] {data}); // for DataTable.Rows.Add
// I can only assume you have a DataTable with one column
foreach(var rowData in data)
yourTable.Rows.Add(rowData);
Hopefully this inspires you.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
txt file that contains several columns of numbers, every column is saved in a double array, what I want to do is get the average of a specific column, but to do that I have to convert the array to a list and then began to calculate. I have this code so far:
List<double> 1 = new List<double>(NumSepaERG);
List<double> 12 = NumSepaERG.ToList();
But i get and error of Invalid Expression term double
Variable names can't start with a numeric character. Change to something like:
List<double> list1 = new List<double>(NumSepaERG);
but you can compute an average using Linq without converting to a list:
double average = NumSepaERG.Average();
If NumSepaERG is a jagged array (an array of arrays), the syntax would be:
double average = NumSepaERG[i].Average();
where i is between 0 and the number of arrays - 1;
I think it's a syntax error, you can't have numbers as variable names. You actually don't even need to make it a list.
double average = NumSepERG.Average();
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm tasked with building a program that performs math based on letters. Every letter has one value. For example, A=1, B=2 and C=3. The user will enter a series of letters in a text box. If the user enters ABC, the result would be 6.
How do I perform this math?
Here is a picture of the user interface I have built:
var text = "Abc";
text = text.ToUpper();
var sum = 0;
foreach (char c in text)
{
sum += c - 64;
}
sum has your value.