web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

AL: Compare two strings alphabetically

(0) ShareShare
ReportReport
Posted on by

Hello,

I have converted my code from C/AL to AL. I can make package and upload it error-free. But I get errors installing it:

CS0019: Operator '<' cannot be applied to operands of type 'string' and 'string'

I want to compare two string alphabetically ( stringA < stringB ).

I cannot find example and functions like Compare, CompareTo, ... does not exists in AL.

Thank You.

Categories:
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    Just tested and this works:

    local procedure TestStrings()
    var
       s1: Text;
       s2: Text;
    begin
       if s1 < s2 then
          Message('test ok');
    end;
  • Community Member Profile Picture
    on at

    Hello,

    It's strange what is not working (i would like to get all names starting with A, B, C and it works OK in C/AL):

    local procedure TestStrings()
    var
       s1: Text;
    begin
       if s1 < "D" then
          Message("starting with A,B,C");
    end;
    - error when installing package (not in VSCode)
    And I've changed code to:
    local procedure TestStrings()
    var
       s1: Text;
       s2: Text;
    begin
      s2 := "D";
       if s1 < s2 then
          Message("starting with A,B,C");

    end;

    - everything is fine

    Regards

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans