敷面膜的字符串字符串、面膜

2023-09-07 10:01:05 作者:没關係,莪們只惿帞甡亽

我读从表中的字符串ID值。当ID是由用户输入的,它是与用户定义的输入掩码完成的,因此掩模本来类似 000-00-0000 ## - ###### AA-9999999 等遮蔽将按照用户的不同,所以必须在运行时进行评价。

I am reading a string ID value from a table. When the ID was input by the user, it was done with an input mask that the user defined, so the mask could have been something like 000-00-0000, ##-######, AA-9999999, etc. The mask will vary by user, and so must be evaluated at runtime.

鉴于只有字母数字文本存储在该表中,什么是产生一个新的字符串与掩模的最佳方式施加?

Given that only the alphanumeric text is stored in the table, what is the best way of generating a new string with that mask applied?

例如:

表值=123456789

Table value = "123456789"

如果用户定义的面具 000-00-0000 ,我想要得到的字符串 123-45-6789

If user has defined mask of 000-00-0000, I want to get string 123-45-6789.

如果用户定义的 AA-9999999 的面具,我想要得到的字符串 12-3456789

If user has defined mask of AA-9999999, I want to get string 12-3456789.

如果用户定义的 FR999_999999 的面具,我想要得到的字符串 FR123_456789

If user has defined mask of FR999_999999, I want to get string FR123_456789.

推荐答案

这不正是我需要的。唯一的缺点是,它关系我到Wi​​ndows窗体组件。

This does exactly what I need. The only downside is that it ties me to the Windows Forms assembly.

        MaskedTextBox mtb = new MaskedTextBox("FR999_999999");
        mtb.Text = "123456789";
        return mtb.Text;