Indexing a char in a string
by admin on dec.04, 2009, under Code
After working with Dynamics NAV (Navision) in five years, I can still be surprised by the small details.
I just did a new discovery that is even documented in the C/SIDE help
I regularly use the COPYSTR function to extract substrings of a string. Even if it was only a single character that I wanted to substring.
When copying the charachter in position 5 … instead of using:
mySubString := COPYSTR(myFullString , 5, 1);
We can use:
mySubString := myFullString[5];
The result is the same, except from the latter where we actually extract a “char” datatype instead of a text string.
There can be circumstances where you have to FORMAT the char. For example if you want to MESSAGE it.
MESSAGE(myFullString[5]);
This won’t work because the MESSAGE function will only display the text datatype and not the char datatype.
This will work:
MESSAGE(FORMAT(myFullString[5]));
No matter if we assigned mySubstring to the char index [5] or return value of the COPYSTR this (below) will of course work.
There is an implicit datatype conversion from char to text when assigning mySubstring.
mySubString := myFullString[5];
MESSAGE(mySubstring);
2 Trackbacks / Pingbacks for this entry
juli 15th, 2010 on 20:49
Buy:Tramadol.Viagra Super Force.Zithromax.Viagra Professional.Viagra.Propecia.Levitra.Cialis.Cialis Professional.Maxaman.Super Active ED Pack.VPXL.Viagra Super Active+.Cialis Super Active+.Viagra Soft Tabs.Soma.Cialis Soft Tabs….
juli 21st, 2010 on 05:11
Buy:Zyban.Valtrex.Synthroid.Mega Hoodia.Human Growth Hormone.Prevacid.Retin-A.Nexium.Lumigan.Actos.Petcam (Metacam) Oral Suspension.100% Pure Okinawan Coral Calcium.Accutane.Arimidex.Zovirax.Prednisolone….