Convert String to Char array in AL code

Was needed in a forum question.

 procedure ConvertStringToCharArray(var arr: array[10] of char; srcStr: Text) var   i: Integer; begin   for i := 1 to strlen(srcStr) do     arr[i] := srcStr[i]; end;
or simply convert a String Element into a char value. 😉
srcStr: Text;chVal: char// get 1. element of the string and convert it to a charchVal := srcStr[1]; .

 

HexToInt in AL code

That was needed in a forum question.

begin  hexStr := 'A2F'; // int value = 2607  intVal := HexToInt(hexStr);  Message(hexStr + ' = ' + format(intVal));end;procedure HexToInt(hexStr: Text): Integervar  len, base, decVal, i, j : Integer;begin  base := 1;  decVal := 0;  len := strlen(hexStr);  for i := 0 to len - 1 do beginj := len - i;if (hexStr[j] >= '0') and (hexStr[j] <= '9') then begin  decVal += (hexStr[j] - 48) * base;  base := base * 16;end else if (hexStr[j] >= 'A') and (hexStr[j] <= 'F') then begin  decVal += (hexStr[j] - 55) * base;  base := base * 16;end;  end;  exit(decVal);end;