source="my number is 999.99"
result="我的数字是999.99"
怎么替换,我的代码:
public void replace()
{
Regex regex = new Regex(@"my number is ([0-9\.]{3,9})");
string result = regex.Replace(@"my number is 999.99", "我的数字是$1"); textBox1.Text = result;
}反正我得不出来我要得结果。求助。

解决方案 »

  1.   

    string result = System.Text.RegularExpressions.Regex.Replace(@"my number is 999.99", @"(-?\d*)\.?\d+", "我的数字是$0");
      

  2.   

    string result = source.Replace("my number is ","我的数字是");
      

  3.   

    string result = Regex.Replace(@"my number is 999.99", @"(?i)my\s+number\s+is\s+([0-9.]{3,9})", "我的数字是$1");
      

  4.   

    根本没有必要用正则:
            public void replace()
            {
                string result = "my number is 999.99".Replace("my number is ", "我的数字是");
                textBox1.Text = result;
            }
      

  5.   

    http://msdn.microsoft.com/zh-cn/library/yd1hzczs.aspx.NET Framework 开发人员指南
    正则表达式选项更新:2007 年 11 月可以使用影响匹配行为的选项修改正则表达式模式。可以通过下列两种基本方法之一设置正则表达式选项:可以在 Regex (pattern, options) 构造函数中的 options 参数中指定,其中 options 是 RegexOptions 枚举值的按位“或”组合;也可以使用内联 (?imnsx-imnsx:) 分组构造或 (?imnsx-imnsx) 其他构造在正则表达式模式内设置它们。在内联选项构造中,一个选项或一组选项前面的减号 (-) 用于关闭这些选项。例如,内联构造 (?ix-ms) 将打开 IgnoreCase 和 IgnorePatternWhiteSpace 选项而关闭 Multiline 和 Singleline 选项。默认情况下,关闭所有正则表达式选项。下表列出了 RegexOptions 枚举的成员以及等效的内联选项字符。请注意,选项 RightToLeft 和 Compiled 只适用于表达式整体而不允许内联。(它们只能在 Regex 构造函数的 options 参数中指定。) 选项 None 和 ECMAScript 不允许内联。IgnoreCase  i  指定不区分大小写的匹配。 
      

  6.   


    那就更没有必要用正则了:public void replace()
    {
      string source = "this is 123, that is 456.";
      string result = source.Replace("this ", "这").Replace("that ", "那").Replace("is ", "是");
      textBox1.Text = result;
    }
      

  7.   

    点“管理菜单” -> “生成帖子”就可刷新帖子了,用不着每次无必要的回复。          |
              |
              |
              |
              |
              |
              |
              |
              V
      

  8.   

    那么,LZ的代码没有问题,能正确工作:using System;
    using System.Text.RegularExpressions;class Program
    {
      static void Main()
      {
        Regex regex = new Regex(@"my number is ([0-9\.]{3,9})");
        string result = regex.Replace(@"my number is 999.99", "我的数字是$1");
        Console.WriteLine(result);     // 輸出:我的数字是999.99
      }
    }
      

  9.   

                string source = "my number is 999.99";            
                Regex thisregex = new Regex(@"[^0-9]+(?=[[0-9]+,[0-9]+\.[0-9]+])");
                string result = thisregex.Replace(source, "我的数字是");
                Console.WriteLine(result);
                Console.ReadLine();
    试下这个..刚测了下结果还可以.