Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a List as following
List<string> email = File.ReadAllLines(fileName).ToList<string>();
filename is text I openFileDialog. The text in file txt is 3 line with 3 gmail
I want convert List to
string[] arRcpt = new string[] { };
The File.ReadAllLines(fileName) returns a string[]. You don't need to convert it into a list and then to string[]. You can directly assign it to an array.
string[] arRcpt = File.ReadAllLines(fileName)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a collection which has strings in it.
Such as:
"iphone x sadasd"
"IPHONE X s325g"
"Another string"
I am adding these strings in a listbox, but not all of them.
I want to add strings into a listbox based on the text entered in a textbox. e.g I might enter the text "iphone x "
So far I have tried:
if(collection.Contains(textBox1.Text));
{
listbox1.items.Add(//string that contains texbox1.text)
}
Use AddRange Method with Where
listbox1.Items.AddRange(collection.Where(x => x.Contains(textBox1.Text));
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
public class itemObject { public string items; }
values - item = "name1,name2" or items = "item3"
Need linq to split by ',' if exists else one string array.
This doesnt require linq, its the default behaviour of String.Split
var array = items.Split(',');
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have comma-separated data in my column called col1, and I have an array of strings
IEnumerable<string> year = {"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000"}
I have tried the following
searchfrom = searchfrom.Where(x => years.Contains(x.col1.Replace(',', ' '))).ToList();
and
searchfrom = searchfrom.Where(x => years.Contains(x.col1)).ToList();
I want that row which is match any "year" into "col1"
To optimize such queries, you should first convert your years collection into a hash set.
var years = new HashSet<string>(new [] { "1990", "1991", ... });
In your Where clause, you need to split the contents of each of your records, x, for which you can use x.Split(','). Then, you need to check whether any of these subparts are contained within the years collection.
var result = searchfrom.Where(x =>
x.Split(',').Any(years.Contains)
).ToList();
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
efStudent.sponsor = Convert.ToString(student.Sponsor);
My problem is that I can't convert the efStudent.sponsor which is a string to student.Sponsor, because it is a string[].
I need some help to convert it from string to string[].
To convert a string to string[], you can initialize a single-element array:
efStudent.sponsor = new string[] { Convert.ToString(student.Sponsor) };
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I had error "cannot convert string[] to string"
string[] digitsArray = {dd, pp, ff, cc};
As digitsArray array of arrays and all "dd, pp, ff, cc" are arrays have string values
I think you want
string[][] digitsArray = {dd, pp, ff, cc};
As if you haven't been given enough solutions already - a LINQ version:
var digitsArray = new[]{dd, pp, ff, cc}.SelectMany(foo=>foo).ToArray();
If you want one-dimensional array - you can use Enumerable.Concat and Enumerable.ToArray:
string[] digitsArray = dd.Concat(pp).Concat(ff).Concat(cc).ToArray();