how can i get byte of text in business central AL?

108 Views Asked by At

I want a similar Encoding.UTF8.GetBytes() in c# Lang to AL Business central

I tried it but it was useless codeunit "Base64 Convert" Base64Convert.ToBase64() I tried to convert c sharp code to AL because can't attach dll in sandbox thank you so much

1

There are 1 best solutions below

0
ChristianBraeunlich On

I haven't had a use case for this yet. You may find what you are looking for in the codeunit 3026 DotNet_Encoding. Since we are not allowed to use DotNet objects in SaaS, the codeunits with the "DotNet_" prefix act as wrappers so that we can still execute the DotNet functionality via these wrapper codeunits. The following example may not be exactly what you are looking for. It is simply an example to give you an idea of what the DotNet_Encoding codeunit contains:

    var
        DotNet_ArrayBytes: Codeunit DotNet_Array;
        DotNet_ArrayChars: Codeunit DotNet_Array;
        DotNet_Encoding: Codeunit DotNet_Encoding;

    procedure EncodingGetBytes()
    var
        resultChar: Char;
    begin
        DotNet_ArrayChars.CharArray(1);
        DotNet_ArrayChars.SetCharValue(261, 0);
        DotNet_Encoding.UTF8();
        DotNet_Encoding.GetBytes(DotNet_ArrayChars, 0, DotNet_ArrayChars.Length(), DotNet_ArrayBytes);

        resultChar := DotNet_ArrayBytes.GetValueAsChar(0);
    end;

As far as I can see the codeunit only accepts an array of chars for now. I have not found a function that allows me to retrieve bytes from a string. Check out the Codeunit DotNet_Encoding for more details. If you are missing a function, you can report an idea via https://aka.ms/bcideas.