Friday Code Fun - X++ TextBuffer Usage
Well Happy Friday to everyone! Man what a fast week this has been. For me short weeks, because of long weekends are great when your in the long weekend. However the work does not go away... just means you have to cram more in a shorten time span.
With that I wanted to have a little code fun Friday post to lead you into the weekend with. I love chances of what I get to jump back into doing development. The Software Engineer in me I guess. At any rate, something I thought might be handy and useful that I would post and pass along is around the use of the TextBuffer class.
The following is the home for the TextBuffer class object for AX 2012.: TextBuffer Class [AX 2012]. It has some useful information, specifically an example of using it to read in a file. However my focus and use for this fun Friday code session is using it to detect numeric only string values.
With that, have a look at the following code segment.:
TextBuffer txtBuff = new TextBuffer();
;
txtBuff.setText("9919190");
txtBuff.regularExpressions(true); //Activate regular expressions
if (txtBuff.find("^[0-9]+$"))
{
// Has numeric only values
}
else
{
// Has Other characters, possibly including numeric values.
}
With the above usage of the TextBuffer class, and turning only Regular Expressions, we can now detect if a string value has numeric only characters, or has other Alpha, or non-numeric characters. This could be useful for several needs when working with Text files and string values in Dynamics AX. Further this logic works with previous versions of AX as well, not just AX 2012.
For those of you wanting to learn more about Regular Expressions, the Wikipedia home is a pretty good source.: Wikipedia: Regular expression
Well that's all for this week, check back soon as I will have a follow up post on the Organization Modeling example, back to Office 2013 + AX 2012, BI, Cloud and much more! Till Next Time!
Labels: AX 2012, Development, Dynamics AX, Dynamics AX 2012, Friday, Fun Friday Code, Microsoft, MSDN, TextBuffer, X++, Xpp
2 Comments:
Nice piece of information.
Nice piece of information.
Post a Comment
<< Home