A Convert Text to Title Case Function for Business Central

DoufuDoufu
1 min read

I realized that there seems to not have a conversion to title case function in Business Central codes, nor have I seen it online. So, sharing is caring ๐Ÿ˜€

    procedure ConvertTitleCase(var InputText: Text): Text
    var
        TextList: List of [Text];
        TextValue: Text;
        OutputString: Text;
    begin
        OutputString := '';
        TextList := InputText.Split(' ');

        foreach TextValue in TextList do begin
            OutputString += UpperCase(CopyStr(TextValue, 1, 1)) + LowerCase(CopyStr(TextValue, 2)) + ' ';
        end;

        exit(OutputString.Trim());
    end;

Have tested this in the Business Central cloud, please let me know if there are any bugs! Thank you!

0
Subscribe to my newsletter

Read articles from Doufu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Doufu
Doufu

Current project developments on Microsoft platforms such as Business Central, Dynamics 365 Sales, Power Platform and occasionally Python. Used to get my paws dirty on Android and Web development.