César Amorim
César Amorim

Reputation: 357

Sublime text2: Replace with a sequence

I have this:

    private void radioButton34_CheckedChanged(object sender, EventArgs e)
    {

    if (radioButton.Checked == true)
        { //blah}
    }

    private void radioButton35_CheckedChanged(object sender, EventArgs e)
    {

    if (radioButton.Checked == true)
        { //blah}
    }

but they are 100 buttons (no joke) I wanna replace 'radioButton.Checked' with 'radioButtonX.Checked' in the sequence, for every radioButton.Checked that he finds, where X starts in 34, and ends in 100

Is it possible? What if i want X to start in 20 or a anyother number? (noob here)

Upvotes: 0

Views: 221

Answers (2)

Xælias
Xælias

Reputation: 868

1/ 1-Step solution
Hit replace (⌥⌘F or ctrl+shift+F (I guess) or Find→Replace...).
Search for (?<=radioButton)(\d+)(_CheckedChanged(?:\n|.)*?radioButton) with RegEx (.*) activated. (see below for explanation on the regex)
And replace with: \1\2\1
RegEx:

  • (?<=radioButton): the string start with radioButton
  • (\d+): it is followed by a bunch of numbers, we store this in \1
  • (_CheckedChanged(?:\n|.)*?radioButton): it is itself followed by _CheckedChange, any number of characters and newLine characters, and radioButton, this is stored in \2
  • replace everything with \1\2\1, which means: keep the numbers, what's after that, and put again the numbers

2/ 2-Step Solution
A little more general solution (not limited to a 2-digit number).
Launch a search: (⌘F or Ctrl+F or Find→Find...). Make sure the Regex box is selected on the left (.*).

Search for: (?<=radioButton)\d+(?=_CheckedChanged)

  • (?<=radioButton): radioButton should be in front of what you search
  • \d+ is any digit, but at least one
  • (?=_CheckedChanged): the number has to be followed by _CheckedChanged

Search for all these. Copy the results. Move all your cursors to the desired location, and paste.

If you have any question :-)

PS:
enter image description here

Upvotes: 3

Lee Moody
Lee Moody

Reputation: 33

This may be a stupid response, but off the top of my head, it should work if _CheckedChanged isn't used anywhere else.

  1. Find all "_CheckedChanged("
  2. Use your left arrow key to go to the end of X (notice multiple cursors)
  3. Hold shift and hit the left arrow key twice to select X
  4. Copy, then using your arrow keys move to radioButton.Checked and hit paste

I just realised you said 100. Obviously the above idea would only work if X is the same number of digits. You'll have to correct the 100th after.

There is surely a better way, but that should do the job I guess. 100 radio buttons!?

Upvotes: 2

Related Questions