Find items in a string collection which contain another string [closed] - c#

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));

Related

Returning a list of objects from a function to a text file C# [closed]

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 1 year ago.
Improve this question
I have a big function that returns a list of objects. I basically need the results to be put in to a text file. The list contains objects of a class with attributes string Index and integer count. I would want it to be written in a textfile like:
Index : Count fe.
BOOK_FROM_STORE : 27
Anybody has some guidance?
Parse the data held by your object to string and then write it to a text file.

How to convert list to string[] [closed]

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)

i want add value number to first element of of text box [closed]

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
txtpayAmount.Text = gblFunction.ConvertTwoDecimal(
txtpayAmount.Text,
btn.Tag.ToString(),
txtpayAmount.SelectedText.Length);
txtpayAmount.Focus();
txtpayAmount.SelectionStart = txtpayAmount.Text.Length;
This is my code , am trying to add the value of button to textbox but its adding as last element of textbox.I want to add as first element
If I understand correctly (your question is confusing), you want prepend the text in a textbox.
If you want to do so you can do a txtBox.Value = 'ValueToPrepend' + txtBox.Value;

How to linq to split string (only if delimer exists) and create array [closed]

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(',');

Combobox text when clearing items [closed]

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 6 years ago.
Improve this question
I'm dealing with the fact that when I clear items in a combobox programmatically, the text do not change and keep the last selected item.
How can I do it?
Try
comboBox.SelectedIndex = -1;
Or
comboBox.Items.Clear();
comboBox.ResetText();
Another way for combo boxes:
Populate
comboBox1.DataSource = new string[] { "", "bruce", "clark", "tony" };
Clear
comboBox1.DataSource = null;

Categories