Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to replace strings in a code
    primarykey
    data
    text
    <p>I want to perform a batch replace operation on a project by following some rules. For e.g. I am taking notes in the code like this:</p> <p>On every code piece, which is commented like this, I want to perform a replace operation, which will replace the input code piece with the output code piece in the following examples:</p> <p><strong>Input 1:</strong></p> <pre><code>//+ a++; //+(+SomeException$SomeMessage) </code></pre> <p><strong>Output 1:</strong></p> <pre><code>try { a++; } catch (AnException) { throw; } catch (Exception ex) { throw new SomeException("SomeMessage", "15", ex); } </code></pre> <p><strong>Input 2:</strong></p> <pre><code>//+ a++; //-(+InvalidOperationException$SomeMessage) </code></pre> <p><strong>Output 2:</strong></p> <pre><code>try { a++; } catch (InvalidOperationException ex) { throw new AnException("SomeMessage", "16", ex); } </code></pre> <p><strong>Input 3:</strong></p> <pre><code>//+ a++; //-(SomeMessage) </code></pre> <p><strong>Output 3:</strong></p> <pre><code>try { a++; } catch (Exception ex) { throw new AnException("SomeMessage", "17", ex); } </code></pre> <p>The magic numbers (15, 16, 17) will increase for each code piece commented like this. I know this is not the best practice but I am not making the decisions and I am expected to handle exceptions like this, so I thought I can ease the pain by taking notes and batch replacing in the end. What is the best way to do this? Should I write my own code to perform replaces or is there some regex replace tool or something like that exist that can automatically make this for me?</p> <p><strong>Update:</strong> This is a one time job and my magic number has to be globally unique. So if it was 25 for the last match in a file, it must be 26 for the first match in the next file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload