String compare

Created at 29 Mar 2015, 14:12
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
HQ

hq76

Joined 29.03.2015

String compare
29 Mar 2015, 14:12


Hi,

How do i get a string compare that return the position of the characters in the string.

I just have to know if a symbol like "EURUSD" got the currency "USD" in it.

When i try :

Print(String.Compare(Symbol.Code, "EUR"));

it returns me "1" with EURUSD symbol chart, but it returns me the same result with GPBUSD chart... What am i doing wrong ? Thank you.

 

 

@hq76
Replies

Invalid
30 Mar 2015, 15:13

Compare is used to check if strings are equal.

Use Contains method

Symbol.Code.Contains("EUR");

 


@Invalid

hq76
30 Mar 2015, 16:57

RE:

Invalid said:

Compare is used to check if strings are equal.

Use Contains method

Symbol.Code.Contains("EUR");

 

Thank you Invalid. But i still need to check if "EUR" is the base currency or not... I know that EUR are always the base currency in forex pairs though.. But i'll have to check the same way for "USD" for instance.

I would like to check if "USD" is the 1st currency in "USDJPY" or the second one in "GBPUSD".

 


@hq76

Invalid
30 Mar 2015, 17:20

RE: RE:
"EURUSD".EndsWith("USD")
//and
"USDJPY".StartsWith("USD")

 


@Invalid

hq76
30 Mar 2015, 21:34

RE: RE: RE:

Invalid said:

"EURUSD".EndsWith("USD")
//and
"USDJPY".StartsWith("USD")

 

Oh thanks a lot, it works. I remembered looking at this function, but it didnt work the first time.


@hq76