2
$\begingroup$

I would love to be able to use the power of Mathematica's patterns to find and replace within my code. I have searched for this on google, and so far I've come up with this: http://reference.wolfram.com/workbench/index.jsp?topic=/com.wolfram.eclipse.help/html/tasks/patterns/findreplace.html

Which seems to suggest that I would need another program, Mathematica Workbench, to do so? Can anyone explain what this is to me? I guess this would involve paying some money to Wolfram

I also had a go with the code written in this thread. It seems to work part of the time, but has some undesirable features (or at least, undesirable to me!). I want to replace all instances of k[i_] with Subscript[k,i] in my code (and I'm sure I would use this for more complex things later on too if I can get it to work now). Here are the current problems that I have, when I run NBReplace[k[i_ ], Subscript[k,i]]

*) Not all cases of k[_] are covered in my code. I can't see why this would be. I don't understand the code for the function in detail, but it looks to me like it should cover all cases

*) The code currently replaces k[_] with k\_Subscript\_i. I guess maybe I need to change an 'InputForm' somewhere to something else? Or I need to get rid of the code that's changing things to be strings?

*) The code replaces the k[_] in the function call itself, how can I make an exception for this cell?

Any help would be greatly appreciated

$\endgroup$

closed as unclear what you're asking by MarcoB, user9660, Jens, Yves Klett, Oleksandr R. May 22 '16 at 1:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ So the question is essentially the same as mine but you are not happy with answers there? $\endgroup$ – Kuba May 17 '16 at 7:39
  • $\begingroup$ Well, yes I'd say that sounds about right. I think I've explained quite clearly why I'm not happy and what else I'd like it to do though. I actually only tried the code in the first and not the second response, but it looks to me like the code in the first response only searches a pattern and doesn't replace it, which isn't what I'm after $\endgroup$ – Joe May 17 '16 at 8:18
  • $\begingroup$ Possible duplicate of Adapting "Find and Replace" functionality to work with Patterns $\endgroup$ – Yves Klett May 20 '16 at 9:42
  • $\begingroup$ I think your question is not very clear, actually. For example: "Not all cases of $k[\_]$ are covered in my code." What does this actually mean? Which cases are missed? Without those examples there is not much that can be said. Your second point is covered by changing the InputForm inside the NotebookWrite call to StandardForm. Also, please use code blocks for your code, not $\LaTeX$ markup. $\endgroup$ – Oleksandr R. May 22 '16 at 1:49
  • $\begingroup$ And you can avoid changing the function call most easily by doing this from a separate notebook. Just add a third argument to NBReplace that specifies the notebook, rather than using SelectedNotebook[] to operate on the current one. $\endgroup$ – Oleksandr R. May 22 '16 at 1:58