我试图从字符串值中删除任何货币符号。正则表达式从字符串中移除任何货币符号?
using System;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string pattern = @"(\p{Sc})?";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
decimal x = 60.00M;
txtPrice.Text = x.ToString("c");
}
private void btnPrice_Click(object sender, EventArgs e)
{
Regex rgx = new Regex(pattern);
string x = rgx.Replace(txtPrice.Text, "");
txtPrice.Text = x;
}
}
}
// The example displays the following output:
// txtPrice.Text = "60.00";
这可行,但它不会删除阿拉伯语中的货币符号。我不知道为什么。
以下是带货币符号的示例阿拉伯字符串。
txtPrice.Text = "ج.م. 60.00";
您是否在表达式中尝试过使用'CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol'? – 2010-11-08 01:21:16
@mootinator,你看到单词'any'吗?您的解决方案将只取代'当前'货币符号 – 2011-12-09 10:01:00
@ taras.roshko您在评论发布13个月后是否养成了讽刺言论的习惯?显然有一个原因是评论而不是答案。 – 2011-12-09 15:13:49