使用变量n regex c#

时间:2017-04-07 08:30:51

标签: c# regex

         var d = new Date();
        string[] weekday = new string[10];
        weekday[0] = "Söndag";
        weekday[1] = "Måndag";
        weekday[2] = "Tisdag";
        weekday[3] = "Onsdag";
        weekday[4] = "Torsdag";
        weekday[5] = "Fredag";
        weekday[6] = "Lördag";
        int day = (int)DateTime.Now.DayOfWeek;
        var n = weekday[day];

        var match = Regex.Match(item.InnerText, @"\b" + n + "\s(.*)\s(.*)\s(.*)", RegexOptions.Multiline);

        Response.Write(match.Value);

当我输入变量时,我在\ s(。)\ s(。)\ s(。)上得到“无法识别的转义序列”错误。当只有@“\bMåndag\ s(。)\ s(。)\ s(。)”,RegexOptions.Multiline)时它才能正常工作;

1 个答案:

答案 0 :(得分:1)

你可以使用@ for regex

struct MyFiles
{
    char fileName[12];
    char fileContents[500];
};
…
    /* Initialize first element. */
    // We can well omit this, since newly allocated bytes of a
    // shared memory object are automatically initialized to 0.
    file[0].fileName[0] = '\0';
    file[0].fileContents[0] = '\0';
…
    /* write to first available array slot in shared memory object */
    for (int i = 0; i < 20; i++)
    {
        if (file[i].fileName[0] == '\0')
        {
            sprintf(file[i].fileName, "%11s", file_name);
            sprintf(file[i].fileContents, "%499s", file_contents);
…
    /* List all filenames. */
    while (file[counter].fileName[0] != '\0')
    {
        puts(file[counter]->fileName);
        counter++;
…