0

Say I have an array of strings

string[] my_array = { "XY:1234567;ZW:124", "XY:124252"};

And a user inputs string user_input = "1234567";

how can I remove the entire string from my_array

so after remove XY:1234567;ZQ:124 is removed based on the partial input

my_array = { "XY:124252" };

My first attempt:

string[] my_array = { "XY:12345678;ZW:124", "XY:124252" };
string user_input = "1234567";
if(my_array.Contains(user_input))
    Console.WriteLine("Inside");
else
    Console.WriteLine("Not Inside");

Outputted Not Inside

My second attempt:

string[] my_array = { "XY:12345678;ZW:124", "XY:124252" };
string user_input = "%1234567%"; // Tried % to do a partial string I think?
if(my_array.Contains(user_input))
    Console.WriteLine("Inside");
else
    Console.WriteLine("Not Inside");

Outputted Not Inside

Im out of ideas

user20929302
  • 383
  • 1
  • 4
  • 14

1 Answers1

1

you need String.Contains(). Try like:

string[] my_array = { "XY:12345678;ZW:124", "XY:124252" };
string user_input = "1234567";
foreach( var item in my_array)
{
   if(item.Contains(user_input))
      Console.WriteLine("Inside");
   else
      Console.WriteLine("Not Inside");
}
apomene
  • 14,282
  • 9
  • 46
  • 72