3

我正在处理从注释中手动清理语义 .n3 和 rdf 文件,并在 C# 中使用 Regex 压缩和漂亮地打印这些文件。

然而#,在描述资源的语义文件中是一个非常常见的字符。

示例代码:

#Processed by Id: cwm.py,v 1.197 2007/12/13 15:38:39 syosi Exp 
        #    using base http://www.prodigi.eu/instances

#  Notation3 generation by
#       notation3.py,v 1.200 2007/12/11 21:18:08 syosi Exp

#   Base was: http://www.prodigi.eu/instances
     @prefix : </ac-schema#> .
    @prefix ins: </instances#> .
    @prefix olanet: <http://www.ibermaticaindustria.com/soluciones/planta-mes-olanet#> .
    @prefix plm: <http://hms.ifw.uni-hannover.de/#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

    ins:everyone     a <http://xmlns.com/foaf/0.1/Group>;
         :canSee ins:public;
         rdfs:member <http://127.0.0.1/OslcOlanetProvider/api/producer/01>,

[...]
4

1 回答 1

3

你可以试试这个:

^\s*#.*$

并替换为空

假设,注释将以 # 开头,或者它前面可能只有 \r 或 \n 或 \t 或 \f \v 或空格

解释

将每个文件读取为字符串并调用以下方法并再次写入文件。

示例代码:

using System;
using System.Text.RegularExpressions;
..........
...........
    public String removeHash(String input)
    {
        string pattern = @"^\s*#.*$";
        string substitution = @"";

        RegexOptions options = RegexOptions.Multiline;

        Regex regex = new Regex(pattern, options);
        string result = regex.Replace(input, substitution);
        return result;
    }
于 2016-12-14T08:31:48.660 回答