之前我在处理 ASCII 的 String 时,都是进行格式化后再输出的,最近偶然间看到了 Print 有一个 %a 参数可以用来直接输出 CHAR8 这样定义的字符串。实验代码如下:
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/ShellCEntryLib.h>
#include <Library/BaseMemoryLib.h>
int
EFIAPI
main (
IN int Argc,
IN CHAR16 **Argv
)
{
CHAR8 Buffer[]="This is a simple test\n\r from www.lab-z.com\n\r";
Print(L"%a", Buffer);
return EFI_SUCCESS;
}
运行结果:
完整的代码下载:
Printa
关于 Print 函数的具体实现,可以在 MdePkg\Library\BasePrintLib\PrintLibInternal.c 中看到。

這個發現 太好啦!!!
每次為了print ascii, 還額外寫print function ,總算有方便的方式了
是啊,以前我也是,搞的蛮折腾
要是我没记错的话AsciiPrint这个函数也是可以的
谢谢哈,我查了一下,应该也可以用
UINTN
EFIAPI
AsciiPrint (
IN CONST CHAR8 *Format,
…
);