Oct 21

Using the built-in string functions in Dynamics NAV usually gives you all the string manipulation options you need. But a common request is replacing a special char with a new string value. This example came from the previous post on SMTP Mail functionality in Pre Dynamics NAV 5 versions. Mads from Denmark, ran into an issue with HTML encoding when using national chars like: æøåÆØÅ. For some reason the HTML emails worked fine at my local computer, here with US locale settings, but changing the values to their HTML encoded equivalent might be a good idea to get better compatability.

Below you will find the simple function for doing this.

Here is a simple example of how to HTML encode my name:

t := 'Søren';
message(t);
InsertVariableValue(t,'ø','ø');
message(t);

InsertVariableValue(VAR Formula : Text[30];VariableName : Text[30];VariableValue : Text[30])
WHILE STRPOS(Formula,VariableName) <> 0 DO BEGIN
Pos := STRPOS(Formula,VariableName);
Formula := DELSTR(Formula,Pos,STRLEN(VariableName));
Formula := INSSTR(Formula,DELCHR(FORMAT(VariableValue),'=',','),Pos);
END;

This function was previously discussed in this post: Evaluate Formulas in Dynamics NAV and also on numerous posts on Mibuso and DynamicsUser. Hope you can use this Mads, and also you other readers :).

Here is a link for you Mads 🙂 :

One Response to “Advanced String Replace Function”

  1. Dave K says:

    This would not work if replacing ” with \” for instance as it would create an infinite loop because it would always find a ” in the string.

    A work around would be running the string replace twice for example:-
    first replace ” with {QUOTE}
    then replace {QUOTE} with \”

Leave a Reply

preload preload preload
pornpants.com pornofri.com kilporn.com