Using Keyword STRPOS in Microsoft Dynamics NAV or Business Central

Using Keyword STRPOS in Microsoft Dynamics NAV or Business Central

In this blog, you will learn about a keyword used in Microsoft Dynamics NAV or Business Central programming called as the ‘STRPOS’. You will also learn how it can make programming in these applications easier.

About the Keyword “STRPOS” and How to Use It

“STRPOS” stands for “String Position.” It is used when you need to get the position of a word or a letter in a certain position in a string.

  1. Once the initial editing of the app.json and launch.json is completed, the next step is to create a file and then code inside the file, as shown in Figure 1.Figure 1 – Messages used with STRPOS keyword in Microsoft Dynamics NAV or Business Central
    There are many things defined in Figure 1. Here is what they are used for:  

    mystring:= ‘Hello i am paymax and i am here to help you. I am a bot and i am designed by a software designer,you can give me the commands to make me do a particular task. You are my Master’;

    Message (‘The string is %1’,StrPos(mystring,‘Master));       

    This is the first message that we have provided.

    Outcome: – This message will provide us the position of the word ‘Master’ that is present in the string.

    mystring:= ‘Hello i am paymax and i am here to help you. I am a bot and i am designed by a software designer,you can give me the commands to make me do a particular task. You are my Master’;

    Message (‘The string is %1’,StrPos(mystring,’I’));

    So, what if I need to get the location of a word in the String?

    Outcome: – As we can see that there are a lot of places where ‘I’ is being used in this string, how does visual studio deals with it is it provides you the first occurring ‘I’ and displays its position.

    Message(‘The string is %1’,StrPos(mystring,‘Bo’));

    This particular one I did for a small learning that whenever we are giving the STRPOS so always remember that it is case sensitive, and it will check first weather the word we are searching for is available in the string.

    Outcome: – It will be delivering us with 0 as it is case sensitive, and we have defined an upper case for ‘Bo’, whereas in the MYstring we said it to be as ‘bo’.

    Message(‘the length of the string is %1’,StrLen(mystring));

    This function is used for the knowing the exact length of our string that we have provided to the system.

    Output: – Always remember it also counts the spaces that we have mentioned in our main text Mystring so it will be giving us the full length of the Mystring including all the punctuation used by us.

    Message(‘The length of the string is %1’,MaxStrLen(mystring));

    This function is used for the knowing the length that we have defined in the VAR section of the string, in respective of our string it will be greater.

    Output: – The Var section we have defined Text [50] so it will be giving us as 50 if our string is less than 50 or otherwise if our string is greater than the defined character so it will give us a different message.​

  2. After creating the code unit, create a page extension where the trigger calls all the messages that have been fired one by one.
    Figure 2 - The creation of the page extension is as in Microsoft Dynamics NAV or Business Central
    Figure 2 – The creation of the page extension is as in Microsoft Dynamics NAV or Business Central
  3. With the page extension ready, deploy it to the server and view the outcomes of the messages.
    Figure 3 - After the deployment of a page extension, the assigned button appears where indicated in Microsoft Dynamics NAV or Business Central
    Figure 3 – After the deployment of a page extension, the assigned button appears where indicated in Microsoft Dynamics NAV or Business Central
    Figure 4 - The first message pops out the length of the Word ‘Master’ in Microsoft Dynamics NAV or Business Central
    Figure 4 – The first message pops out the length of the Word ‘Master’ in Microsoft Dynamics NAV or Business Central​
    Figure 5 - As it is case sensitive, it searches for 'I' and then the position of 'I' is given by it in Microsoft Dynamics NAV or Business Central
    Figure 5 – As it is case sensitive, it searches for ‘I’ and then the position of ‘I’ is given by it in Microsoft Dynamics NAV or Business Central

    Figure 6 – The query was for 'Bo' and it is case-sensitive, so the system gives 0 as there is no occurrence of 'Bo' in Microsoft Dynamics NAV or Business Central
    Figure 6 – The query was for ‘Bo’ and it is case-sensitive, so the system gives 0 as there is no occurrence of ‘Bo’ in Microsoft Dynamics NAV or Business Central​
    Figure 7 - The total length of the String is given by the next message in Microsoft Dynamics NAV or Business Central
    Figure 7 – The total length of the String is given by the next message in Microsoft Dynamics NAV or Business Central

    Figure 8  - The Maximum length that we defined in the VAR section of the code is given here in the message in Microsoft Dynamics NAV or Business Central
    Figure 8  – The Maximum length that we defined in the VAR section of the code is given here in the message in Microsoft Dynamics NAV or Business Central​
    Figure 9 - An example if the VAR is defined with a less length than the string, generating a message in Microsoft Dynamics NAV or Business Central
    Figure 9 – An example if the VAR is defined with a less length than the string, generating a message in Microsoft Dynamics NAV or Business Central

If you have any questions about string position or other Dynamics NAV or Business Central questions for any version, contact ArcherPoint.

Read more “How To” blogs from ArcherPoint for practical advice on using Microsoft Dynamics Business Central or NAV.

If you are interested in NAV/Business Central development, check out our collection of NAV or Business Central Development Blogs.

 

Trending Posts

Stay Informed

Choose Your Preferences
First Name
*required
Last Name
*required
Email
*required
Subscription Options
Your Privacy is Guaranteed