VB6格式功能:模拟在.NET功能、格式、NET

2023-09-03 05:55:24 作者:拽拽的蚂蚁zZZ

的String.Format 函数,称为文档作为模拟为格式从VB6功能。还有格式的VisualBasic 命名空间功能,提供了兼容的,基本上有同样的权力,的String.Format

There is String.Format function that is referred to in the documentation as the analog for Format function from VB6. There's also Format function from VisualBasic namespace that is provided for compatibility and basically has same powers as String.Format.

事实上,这两个格式的日期和数字。

Indeed, those two format dates and numbers.

不过,VB6的功能还能够格式化字符串:

But VB6's function was also able to format strings:

? format$("hi there", ">")
HI THERE
? format$("hI tHeRe", "<")
hi there
? format$("hi there", ">!@@@... not @@@@@")
HI ... not THERE

的String.Format 是不是能够做到这一点,就我而言,也不是新的格式。我也找不到任何提及在兼容性格式文档的VB6的某部分功能丧失,好像特点是去precated悄无声息。

String.Format is not able to do that, as far as I'm concerned, nor is the new Format. I also couldn't find any mention in the compatibility Format documentation that certain parts of VB6 functionality is lost, seems like the feature was deprecated "silently."

这有什么的框架,可以做到这一点类型的格式?

Is there anything in the framework that can do this type of formatting?

推荐答案

另一种解决方案来看看是用Microsoft.VisualBasic.Compatibility.VB6命名空间,其中包含几个类和方法是使用Visual Basic 6向后兼容。它主要是为了升级工具,而且可以节省您不必购买迁移工具或写code自己的麻烦。

Another solution to look at is to use the Microsoft.VisualBasic.Compatibility.VB6 namespace, which contains several classes and methods that are backwards compatible with Visual Basic 6. It's primarily meant for upgrade tools, but it will save you the hassle of having to purchase a migration tool or write the code yourself.

MSDN文档: Support.Format方法(Microsoft.VisualBasic.Compatibility.VB6)

的参数不改变,它基本上支持相同的功能的至少给定的例子:

The parameters don't change and it basically supports the same functionality at least given your examples:

Imports Microsoft.VisualBasic.Compatibility.VB6

Console.WriteLine("HI THERE ")
Console.WriteLine(Support.Format("hi there", ">"))

Console.WriteLine("hi there ")
Console.WriteLine(Support.Format("hI tHeRe", "<"))

Console.WriteLine("HI ... not THERE")
Console.WriteLine(Support.Format("hi there", ">!@@@... not @@@@@"))