字符串填充和对齐

时间:2015-12-14 16:11:40

标签: axapta microsoft-dynamics dynamics-ax-2012 dynamics-ax-2012-r2 dynamics-ax-2012-r3

我今天尝试使用TextIo保存文件。只有3行:

Radio Station;MagicFM
Test;This is jost for testing purpose.
TV;TV_Brand

一切都好,但后来我读了。

enter image description here

我无法调整事物。

可能类似:

Radio Station         - MagicFM
Test                  - This is jost for testing purpose.
TV                    - TV_Brand

这就是我在代码中所拥有的:

info(strFmt("%1  - %2", strLFix( conPeek(con, 1), 20),conpeek(con, 2)));

我用strRFix和strLFix玩了一下但没有运气..有没有简单的方法来实现这个目标?

3 个答案:

答案 0 :(得分:3)

Aligning output like this is not the intended use of infolog, and as Matej said, the reason is because of the font. However, if you are wanting to use the infolog for display purposes, you probably will want to use it like this to get the following output:

static void Job114(Args _args)
{
    container       c, cc;
    int             i;

    c = [["Radio Station", "MagicFM"], ["Test", "This is jost for testing purpose."], ["TV", "TV_Brand"]];
    setPrefix("Output"); // SetPrefix is necessary to get the tabbing to function correctly
    for (i=1; i<=conLen(c); i++)
    {
        cc = conPeek(c, i);
        info(strFmt("%1\t%2", conPeek(cc, 1), conPeek(cc, 2)));
    }
}

enter image description here

答案 1 :(得分:1)

您必须使用Courier之类的Fixed width font。您无法使用可变宽度字体直观对齐。

答案 2 :(得分:1)

You could try to use the System.String.Format method like:

str       s; 
s = System.String::Format("{0, -15} - {1, -15}", "Radio Station", "MagicFM");    
info(s);

See Align String with Spaces, strFmt Function [AX 2012] and String.Format Method for more information.