有没有一种方法以编程方式转换VB6格式化字符串格式化.NET字符串? [英] Is there a way to programmatically convert VB6 Formatting strings to .NET Formatting strings?

查看:124
本文介绍了有没有一种方法以编程方式转换VB6格式化字符串格式化.NET字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 有谁知道VB6格式化字符串一个很好的参考呢?

  2. 有谁知道从VB6格式字符串转换器到.NET字符串?

我正在移植一个大VB6 code基地.NET。它是一个数据库为中心的软件,和数据库本身持有的VB6格式串它们后来加载和使用在数据库中,以显示其他数据。

I'm working on porting a large VB6 code base to .NET. It is a database centric piece of software, and the database itself holds VB6 format-strings which are later loaded and used to display other data in the database.

我的问题,如这篇文章,是如何端口这一点。但选择该问题的答案是不能满足我的需求。我不舒服靠着专门为我专门聘请来港码头的语言向后兼容性设计库。

My question, like this article, is how to port this. However the answer chosen for that question isn't adequate for my needs. I'm uncomfortable relying on libraries specifically designed for backwards compatibility with a language I've been specifically hired to port away.

推荐答案

格式化例程VB6使用实际上是建立在操作系统中。的oleaut32.dll,所述VarFormat()函数。它的存在了15年,将围绕永远,考虑多少code依赖于它。试图格式化字符串转换为一个.NET复合格式化字符串是一个没有希望的任务。只需使用操作系统的功能。

The formatting routine that VB6 uses is actually built into the operating system. Oleaut32.dll, the VarFormat() function. It's been around for 15 years and will be around for ever, considering how much code relies on it. Trying to translate the formatting strings to a .NET composite formatting string is a hopeless task. Just use the OS function.

下面是做到这一点的一个示例程序,使用的例子来自链接线:

Here's a sample program that does this, using the examples from the linked thread:

using System;
using System.Runtime.InteropServices;

class Program {
    static void Main(string[] args) {
        Console.WriteLine(Vb6Format("hi there", ">"));
        Console.WriteLine(Vb6Format("hI tHeRe", "<"));
        Console.WriteLine(Vb6Format("hi there", ">!@@@... not @@@@@"));
        Console.ReadLine();
    }

    public static string Vb6Format(object expr, string format) {
        string result;
        int hr = VarFormat(ref expr, format, 0, 0, 0, out result);
        if (hr != 0) throw new COMException("Format error", hr);
        return result;
    }
    [DllImport("oleaut32.dll", CharSet = CharSet.Unicode)]
    private static extern int VarFormat(ref object expr, string format, int firstDay, int firstWeek, int flags,
        [MarshalAs(UnmanagedType.BStr)] out string result);
}

这篇关于有没有一种方法以编程方式转换VB6格式化字符串格式化.NET字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆