GSe*_*erg 4 .net vb.net string-formatting vb6-migration
有一个String.Format函数在文档中被称为FormatVB6 函数的模拟。还有Format来自VisualBasic命名空间的函数是为了兼容性而提供的,并且基本上具有与String.Format.
事实上,这两种格式的日期和数字。
但是 VB6 的函数也能够格式化字符串:
? format$("hi there", ">")
HI THERE
? format$("hI tHeRe", "<")
hi there
? format$("hi there", ">!@@@... not @@@@@")
HI ... not THERE
Run Code Online (Sandbox Code Playgroud)
String.Format就我而言,无法做到这一点,新的Format. 我在兼容性Format文档中也找不到任何提及VB6 功能的某些部分丢失的内容,似乎该功能已被“悄悄地”弃用。
框架中有什么东西可以进行这种类型的格式化吗?
另一个要考虑的解决方案是使用 Microsoft.VisualBasic.Compatibility.VB6 命名空间,它包含几个向后兼容 Visual Basic 6 的类和方法。它主要用于升级工具,但它可以为您省去必须升级的麻烦购买迁移工具或自己编写代码。
MSDN 文档:Support.Format 方法 (Microsoft.VisualBasic.Compatibility.VB6)
参数不会改变,至少在您的示例中,它基本上支持相同的功能:
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 @@@@@"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7874 次 |
| 最近记录: |