using System;
using System.IO;
class Test
{
public static void Main()
{
try
{
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line = sr.ReadToEnd();
Console.WriteLine(line);
}
string pattern1 = @"(in cm)";
string pattern2 = @"mm";
Regex rgx1 = new Regex(pattern1);
Regex rgx2 = new Regex(pattern2);
Regex rgx3 = new Regex(pattern3);
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
如何在 C# 中使用正则表达式将以下 cm 从文件转换为 m:
rectangle (in cm) 20 H * 40 W and circle diameter 30 mm