我在尝试获得所需的输出时陷入困境。它实际上是我在另一个问题中面临的字符串分离问题。
// Inputs String input1 = "=DIVIDE(Input!RC,Input!R[1]C)"; // B1 String input2 = "=DIVIDE(MULTIPLY(Input!R[-1]C,Input!R[1]C),100)"; // B2 String input3 = "=Input!R[-2]C + R[-1]C"; // B3 String input4 = "=DIVIDE(R[-2]C,Input!R[-2]C)"; // B4 String input5 = "=R[-4]C+R[-1]C"; // B5
现在,我必须用适当的 B 值替换 RC。
以 input5 为例,我将查看 R[-4]C,然后从其 input5 开始,我将添加 (-4) 和 (5) 以获得 1,并将 R[-4]C 替换为 B1。
对于所有人来说都是一样的。
// Desired output // =DIVIDE(Input!B1,Input!B2) // =DIVIDE(MULTIPLY(Input!B1,Input!B3),100) // =Input!B1+calc!B2 // =DIVIDE(calc!B2,Input!B2) // =calc!B1+calc!B4
任何人都可以告诉我如何实现这一目标吗?
最佳答案
这是一些想法:
identify offset (1 for input1, 2 for input2 etc)
for each match of "R" ( "[" DIGIT+ "]" )? "C"
if DIGIT+ != "" then <index> = offset + tonumber(DIGIT+) else <index> = offset
replace match with B<index>
关于Java字符串分离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14758459/