Login Page - Create Account

Support Board


Date/Time: Tue, 21 Jan 2025 12:20:46 +0000



[Programming Help] - String Compare function

View Count: 1839

[2018-08-21 12:55:53]
Richard Chinn - Posts: 28
Hi Guys,

I am having trouble with the string compare function.
The documentation is unclear to me and it lists the same function twice but not the same way as in the example so I am not sure if I am doing something wrong.

How To Compare Strings
You can compare a SCString to another string using the SCString CompareNoCase(const char* String, int NumChars) or SCString CompareNoCase(SCString String, int NumChars) functions.
These functions compare String to the string in the SCString these functions are called from, using a case-insensitive comparison up to the first NumChars characters of the two strings.
If NumChars is left out, then the function compares all the characters of the two strings.
The function returns 0 if both strings are equal up to the given length, an integer < 0 if String is lexically less than the string in SCString, and an integer > 0 if String is lexically greater than the string in SCString.

Code Example
int Result;
Result = sc.Symbol.CompareNoCase("ABC");

SCString SymbolToCompare("ABC");
Result = sc.Symbol.CompareNoCase(SymbolToCompare);


It works like I think it should if I do these:
SCString abc = "ABC";
SCString def = "DEF";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 0

SCString abc = "ABC";
SCString def = "ABC";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 1

It doesn't work like I think it should if I do these:

SCString abc = "ABC";
SCString def = "AB1";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 1

SCString abc = "ABC";
SCString def = "A1C";
int result = sc.Symbol.CompareNoCase(abc) == sc.Symbol.CompareNoCase(def); // returns 1

I also tried these using the NumChars parameter with the same result.

Thanks,
Richard
[2018-08-22 10:16:17]
Marmany - Posts: 307
For info
sc.Symbol gets current chart symbol.
[2018-08-22 13:09:25]
Richard Chinn - Posts: 28
Thank Marmany,

I am not having trouble getting the symbol. I'm actually using the sc.GetRealTimeSymbol() function for that.
I am trying to compare the symbols on different charts to make sure they are set to the correcy symbol for my study.
Comparing the strings is the only way I know to attempt this.
Is there another way that you are aware of?

Thanks,
Richard
[2018-08-22 14:16:58]
Marmany - Posts: 307
Richard, this example in Studies.cpp line 5673- should help you with the code:

  SCString Message;
  int ReturnValue;
  Message.Format("This here is a Test");
  ReturnValue = Message.CompareNoCase("This is a test");
[2018-08-22 18:32:50]
Richard Chinn - Posts: 28
Thanks Marmany!!

That did help clarify it alot!
I got it to work as expected.
The documentation is not very clear on this function.

I really appreciate you taking the time to help me with this.

Richard

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account