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 :
Microsoft Dynamics AX (Archived)

Like operator in Switch Case statements?

(0) ShareShare
ReportReport
Posted on by

Does anyone know if there is a way to use a wildcard in a switch statement?

I know in an if statement this is valid

str string = "whatever comes after whatever";
if (string like "whatever*")
{
info("Works");
}


but is it possible to do with with a switch? i haven't been able to find a good way to do it except for the following work around, which has a caveat.

str string = "whatever comes after whatever";
str startswithstring;
;
startswithstring = substr(string, 8, -8); //but what if you dont know the length of the string?
switch (startswithstring)
{
case "whatever" :
info("works");
break;
}


so its ok if you know the exact length of the string in which you want to search.  but what if the string is of an unknown length?  this workaround would only be good if you knew the length of the original string.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Hi itemLouks,
    Any switch could be replaced with multiple "if .. else if", what is the reason to use switch ?

    If you want to do this you can use next code:

    switch (true)
    {
        case (string like "whatever*") :
            info("works");
            break;
    }


  • Community Member Profile Picture
    on at

    I have written a method that uses a stringedit to function as a "smart filter".  So depending on what is typed into the stringedit i can use in a query in different field ranges and values or perform different calculations all from one textbox.  In doing so i have created quite a large nested if statement. While it does work, it is just plain ugly and hard to read.

  • Community Member Profile Picture
    on at

    its funny i tried 100 different ways i never thought to just put (true) after the switch.  It makes sense now i really appreciate the help.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans