Compare strings!

For general Flowcode discussion that does not belong in the other sections.
Post Reply
jgu1
Posts: 910
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 804 times
Been thanked: 200 times

Flowcode v11 Compare strings!

Post by jgu1 »

Hi all!


Inside an If decision I can write: String_One = String_Two, it working.

In Built_in_funktion fs is the CompareS( ), how do I use this in an If funktion I have test with CompareS( String_One, String_Two ) and more attemp?

I have seach in Wiki but can´t find examble and what is best :)

Thank´s
Attachments
String_Compare.fcfx
(7.63 KiB) Downloaded 29 times

BenR
Matrix Staff
Posts: 2155
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 584 times
Been thanked: 769 times

Re: Compare strings!

Post by BenR »

Hello,

The decision and the compare function both end up with similar c code.

To use the compare function you do this

Result = compare$(str1, str2, case)

Result is 0 if the strings match.

Case is 0 for case insensitive or 1 for case sensitive.

The new str1 = str2 in the decision allows for a shorthanded way of writing compare$(str1, str2, 1) == 0

jgu1
Posts: 910
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 804 times
Been thanked: 200 times

Re: Compare strings!

Post by jgu1 »

Thank you Ben :lol:

Steve-Matrix
Matrix Staff
Posts: 1815
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 260 times
Been thanked: 419 times

Re: Compare strings!

Post by Steve-Matrix »

Just to add, the result of the "Compare$" function can also be used to determine whether the strings are "higher" or "lower" than each other. For example, see this:

Code: Select all

s1 = "abc"
s2 = "abd"
result = Compare$(s1, s2, 0)
In this case, "result" would be equal to -1 in simulation because "abc" is less than "abd" alphabetically.

Similarly, Compare$("yes", "no", 0) would return 1 (because "yes" is after "no" alphabetically).

Well, actually it's more than alphabetically because it works the same way for the whole ascii character set, e.g. "!!" < "??" and so Compare$("!!", "??", 0) would return -1.

Note that the above is how the simulation within Flowcode works.

It may be different in the actual code running on a chip. I've just checked and the 8-bit PIC targets return "0" for equal, "1" for greater than, and "255" for less than. So it's similar, but "255" is returned instead of "-1".

Steve-Matrix
Matrix Staff
Posts: 1815
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 260 times
Been thanked: 419 times

Re: Compare strings!

Post by Steve-Matrix »

Also, the direct string comparison current only works with the "is equal to" ("==" / "=") and "is not equal to" ("<>" / "!=") operators. We may change this in a future release so it also works with "greater than" (etc).

jgu1
Posts: 910
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 804 times
Been thanked: 200 times

Flowcode v11 Re: Compare strings!

Post by jgu1 »

Hi Steve!

Thank you for your explanation and examble, I will play and test your tip it make sense, for me, thank´s :D

In FC10 it is possible to to call/add the compare string from the If decision (f§) in the drop down list, it is not visible in F11, I have to add a Calculation box and find it this way?

Jorgen

BenR
Matrix Staff
Posts: 2155
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 584 times
Been thanked: 769 times

Re: Compare strings!

Post by BenR »

Hi Jorgen,

It's certainly possible to use this in a decision icon in v10.

Code: Select all

compare$(str1, str2, 1) == 0
However I don't think you can select/choose the function from a drop down list inside the decision icon.

jgu1
Posts: 910
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 804 times
Been thanked: 200 times

Re: Compare strings!

Post by jgu1 »

Hi Ben!

Sorry, I am not so good to explain. I think if you look at the att picture you see what I mean I could not see the " F§ " in FC11 I have not expand the window in FC11 :lol:
Sorry for the inconvenience :) and thak´s

Br Jorgen
Attachments
Fc10.png
Fc10.png (64.91 KiB) Viewed 24 times

Post Reply