Rascal:字符串拆分函数

问题描述 投票:0回答:1

是否可以在rascal中的字符串上使用split()时保留文字分隔符?

例如,

split("/*", line)

string split separator rascal
1个回答
0
投票

我能够创建自己的分割功能。这不是完美的,但似乎可以解决我之前遇到的问题。

public list[str] splitString(list[str] fileLines)
{
    list[str] splitList = [];

    for(line <- fileLines)
    {
        if( /^<x:.*>\/\*<y:.*>$/ := line)
        {
            splitList = splitList + x;
            splitList = splitList + "/*";
            splitList = splitList + y;
        }
        else if(/^<x:.*>\*\/<y:.*>$/ := line)
        {   
            splitList = splitList + x;
            splitList = splitList + "*/";
            splitList = splitList + y;
        }
        else
        {
            splitList = splitList + line;
        }
    }

    return splitList;
}
© www.soinside.com 2019 - 2024. All rights reserved.