Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Finding the start of string

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Im looking to write an if statement as follows:

If the string begins with "abc" then changecompany to 1

If not then changecompany to 2.

Im new to c/al so I do not know how to do this.

*This post is locked for comments

  • Suggested answer
    Zaid Tariq Profile Picture
    Zaid Tariq 2,266 on at
    RE: Finding the start of string

    Hi,

    Do like as follow:

    TextToCompareWith := 'abc';
    IF COPYSTR(MyString,1,STRLEN(TextToCompareWith)) = TextToCompareWith THEN
    MyRec.CHANGECOMPANY('MyCompanyName 1')
    ELSE
    MyRec.CHANGECOMPANY('MyCompanyName 2');

    For more details have a look:

    [View:https://msdn.microsoft.com/en-us/library/dd338929.aspx:750:50]

    [View:https://msdn.microsoft.com/en-us/library/dd338944.aspx:750:50]

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans