转换 c++ printf 格式与 VB .NET 字符串格式之间的转换
我有一些 VB .NET 软件,可以连接到大量旧的(但健全的)COM 对象。 VB 为 COM 对象提供了一个 GUI,其中一部分包括在 COM 对象上设置各种选项 - 其中一些选项与字符串格式相关。
我有一对简单的 VB .NET 函数,它们使用涵盖特定常见字符串的大型选择案例将基本 %f、%d、%g 格式转换为 .NET 等效格式,但它们并不涵盖所有格式。这就是我所拥有的……
ElseIf f = "%.3f" Then
return "0.000"
ElseIf f = "%.2f" Then
return "0.00"
ElseIf f = "%.1f" Then
return "0.0"
在我开始深入研究并通过一些解析使其更加通用之前,有人知道有一个类(例如 VB 或 C# .NET)可以提供不错的现成实现吗?或者也许可以使用一些正则表达式向导?
非常感谢
蒂姆
I have some VB .NET software that interfaces to a load of old (but sound) COM objects. The VB provides a GUI for the COM objects, part of which consists of setting various options on the COM objects - several of which relate to string formatting.
I have a simple pair of VB .NET functions that convert basic %f, %d, %g formats to/from .NET equivalents using a large select case covering specific common strings, but they don't cover all formats. This is the kind of thing I have...
ElseIf f = "%.3f" Then
return "0.000"
ElseIf f = "%.2f" Then
return "0.00"
ElseIf f = "%.1f" Then
return "0.0"
Before I start diving in and making it more versatile with some parsing, does anyone know of a class (eg VB or C# .NET) that provides a decent ready-made implementation? Or perhaps some regexp wizadry could be used?
Many thanks
Tim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否真的需要这两种格式,或者您的用户采用一种格式,而另一种格式在您的软件的实现细节中使用 - 但如果您具有直接识别用户选项的字符串格式化函数,则可能会消失?
Do you really need both formats, or is one format adopted by your users and the other is used inside the implementation details of your software -- but could go away if you had string formatting functions that recognized your users' options directly?
你不需要。 Windows 内置了这种格式。您可以简单地从 User32.dll P/Invoke
wsprintf
。You don't need to. Windows has that formatting built-in. You can simply P/Invoke
wsprintf
from User32.dll.