Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Contains() : Multiple character - C#

Tags:

string

c#

I have this piece of code:

description="EUR CMS Swap";
description_token=description.Split(" ".ToCharArray());
bool check;

if(description_token.Contains("EUR CMS"))
   check=true;

But check is always false, even though

description_token[0]="EUR"  
description_token[1]="CMS"

What am I doing wrong? Is there an alternative method?

like image 234
7raiden7 Avatar asked Feb 19 '26 14:02

7raiden7


1 Answers

The source value you have gets split into the array by spaces, so you should have three objects in your array

(EUR, CMS and Swap)

So you should rewrite your check to be

if(description_token.Contains("EUR") || description_token.Contains("CMS"))

(if it is enough if just one of the values is inside that array)

or

if(description_token.Contains("EUR") && description_token.Contains("CMS"))

(if both values HAVE to be inside that array)

like image 200
DrCopyPaste Avatar answered Feb 22 '26 03:02

DrCopyPaste



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!