我的主要问题是试图找到合适的解决方案来自动启用此功能,例如:

d+c+d+f+d+c+d+f+d+c+d+f+d+c+d+f+

到这个:
[d+c+d+f+]4

即找到彼此相邻的重复项,然后从这些重复项中进行较短的“循环”。
到目前为止,我没有找到合适的解决方案,我期待得到答复。附言为避免混淆,上述示例并不是唯一需要“循环”的内容,它随文件的不同而不同。哦,这是供C++或C#程序使用的,虽然我也可以接受其他建议,但都可以。同样,主要思想是所有工作将由程序本身完成,除了文件本身外,无需用户输入。
这是我对延伸页面的致歉的完整文件,以供引用:
#0 @ 16 v225 Y10 W250 T76

16岁
$ ED $ EF $ A9
20
> ecegb> d > d + d + f + a +> c + f + d + > c cegbgegec ec >
d + c + d + f + d + c + d + f + d + c + d + f + d + c + d + f +
r1 ^ 1

/
88
r1r1r1r1
f +
f + g + cg + r4
a + c + a + g + cg + r4f +
f + g + cg + r4
a + c + a + g + cg + r4f +
f + g + cg + r4
a + c + a + g + cg + r4
f +
f + g + cg + r4
a + c + a + g + r4g + 16f16c +
a + 2 ^ g + f + g + 4
f + ff + 4fd + f4
d + c + d + 4c + c
> c4d +
a +> c + d + 4g + 4a + 4
r1 ^ 2 ^ 4 ^ a + 2 ^ g + f + g + 4
f + ff + 4fd + f4
d + c + d + 4c + c
> c4d +
a +> c + d + 4g + 4a + 4
r1 ^ 2 ^ 4 ^
r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1

#4 @ 22 v250 y10

88
o3
rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg + rg +
/
r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1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cr2
cr2
c + 4 ^ cr2
cr2
c + 4 ^ cr2
a + 4 ^> cr2
c + 4 ^ cr2
cr2
c + 4 ^ c
r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1
22
f + 4 ^ fr2
d + 1f + 4 ^ fr2
d + 1
c + 4 ^ cr2
> c + 4 ^ cr2
r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1r1

最佳答案

不知道这是您在寻找什么。

我将字符串“testtesttesttest4notaduped + c + d + f + d + c + d + f + d + c + d + f + d + c + d + f + testtesttest”转换为“[test] 4 4notadupe [ d + c + d + f +] 4 [测试] 3“

我确信有人会提出更好,更有效的解决方案,因为在处理完整文件时会有点慢。我期待其他答案。

        string stringValue = "testtesttesttest4notaduped+c+d+f+d+c+d+f+d+c+d+f+d+c+d+f+testtesttest";

        for(int i = 0; i < stringValue.Length; i++)
        {
            for (int k = 1; (k*2) + i <= stringValue.Length; k++)
            {
                int count = 1;

                string compare1 = stringValue.Substring(i,k);
                string compare2 = stringValue.Substring(i + k, k);

                //Count if and how many duplicates
                while (compare1 == compare2)
                {
                    count++;
                    k += compare1.Length;
                    if (i + k + compare1.Length > stringValue.Length)
                        break;

                    compare2 = stringValue.Substring(i + k, compare1.Length);
                }

                if (count > 1)
                {
                    //New code.  Added a space to the end to avoid [test]4
                    //turning using an invalid number ie: [test]44.
                    string addString = "[" + compare1 + "]" + count + " ";

                    //Only add code if we are saving space
                    if (addString.Length < compare1.Length * count)
                    {
                        stringValue = stringValue.Remove(i, count * compare1.Length);
                        stringValue = stringValue.Insert(i, addString);
                        i = i + addString.Length - 1;
                    }
                    break;
                }
            }
        }

10-10 00:53