Talk:String validation

From Axaptapedia

Jump to: navigation, search

Hi there,

I would not recommend using containers in this way, as their performance is quite bad. Using this function in large scale can degrade performance on a larger scale.

Instead I would recommend using either the built-in regular expression system (global function "match") or, if you need a more powerful tool, link into the Visual Basic Regex COM Objects like Infolog stack trace does. The latter is extremly powerful and, for example allows even complex validations like E-Mail addresses or VAT Numbers of countries like Great Britain (the Regex for GB is something like '^GB((\\d{9}(\\d{3})?)|((GD|HA)\\d{3}))$').

As well, both strrem and strkeep are available in Ax 3.0.

In case you need to iterate often over a list of elements, make the list static (f.x. using a Singelton or some globally cached object) and then use the Foundation Class "list", which is optimized for element traversal using its iterators:

   List directories = this.GetTheListSomehow();
   ListEnumerator iter = directories.getEnumerator();
   ;
   
   while(iter.moveNext())
   {
       if (! WinAPI::folderExists(iter.current()))
           WinAPI::createDirectory(iter.current());
   }

This provides for fast and easy traversal. Note, that the ListEnumerator is much easier to use in this context as the ListIterator is. This goes for all foundation classes, the Enumerators implement the Iterator concept more closly, especially if you come from C++ or C#, where the above constructs are quite common.

Personal tools
Microsoft Community
Microsoft Dynamics Ax Community