是否有一个免费实现的printf对.NET的?有一个、printf、NET

2023-09-04 07:17:30 作者:突然好想你

的问题:

我不能使用的String.Format,我有C形式的格式字符串; 在我不能调用本机的printf(无P / Invoke的); 我不能使用http://www.$c$cproject.com/KB/printing/PrintfImplementationinCS.aspx因为许可证的,我需要的东西GPL兼容的。 I can't use string.Format, I have C style format strings; I can't call the native printf (no P/Invoke); I can't use http://www.codeproject.com/KB/printing/PrintfImplementationinCS.aspx because of the license, I need something GPL-compatible.

有.NET Framework的一个免费实现的printf / sprintf的呢?除了上面的链接,我无法找到任何东西。

Is there a free implementation of printf/sprintf for the .net framework? Other than the above link, I couldn't find anything.

谢谢!

更新:

感谢您的帮助,即使你什么也找不到。这意味着我就必​​须这样做我自己(我试图避开它,但哦...) 我做了一个sprintf的功能,它支持基本的格式字符串,你可以在这里找到: https://sourceforge.net/projects/printfnet/ 。我会尽量做到完整实现,如果我能。

Thanks for the help, even though you couldn't find anything. That means I'll just have to do it myself (I was trying to avoid it, but oh well...) I cooked up a sprintf function that supports basic format strings, you can find it here: https://sourceforge.net/projects/printfnet/. I'll try to make it a complete implementation if I can.

推荐答案

我想你想要这样的: HTTP://www.$c$cproject.com/KB/printing/PrintfImplementationinCS.aspx

I think you want this: http://www.codeproject.com/KB/printing/PrintfImplementationinCS.aspx

这是一个免费的执行的C 的端口的printf 函数为C#。你应该知道的作者指出,目前不支持是所有功能的printf - 但这可能是一个很好的起点。

It's a free implementation of a port of the C printf function to C#. You should be aware the author points out that not all features of printf are currently supported - but this may be a good starting point.

编辑:我看到,该版本的许可证是不是与你所需要的兼容 - 在这种情况下,我肯定会推荐看直接调用非托管版本,下面的博客文章讨论。这可能是最适合的,最安全的做法。的

如果不剪,这里是关于实际调用非托管的printf 功能的博客文章:

If that doesn't cut it, here's a blog article about actually calling the unmanaged printf function:

http://community.bartdesmet.net/博客/捷运/存档/ 2006/09/28 / 4473.aspx

看起来这是所有你需要调用非托管的printf 从C#:

It looks like this is all you need to call the unmanaged printf from C#:

[DllImport("msvcrt40.dll")]
public static extern int printf(string format, __arglist);

static void Main(string[] args)
{
   printf("Hello %s!\n", __arglist("Bart"));
}