[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a simple string manipulation
From: |
Pascal Bourguignon |
Subject: |
Re: a simple string manipulation |
Date: |
06 Apr 2003 06:16:49 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
Luca Ferrari <fluca1978@libero.it> writes:
> Hi to everyone,
> I've got a simple problem (I think) that is related to a string manipulation.
> I must write often strings like this:
> MOVE A TO B
>
> and after it's opposite
> MOVE B TO A
>
> Now I'd like to know if there's a way to set a key function so that
> after I've got a group of strings I can simply copy and paste and
> revert they. Can you shown me how? Thanks
I would do:
M-x replace-regexp
MOVE \(.*\) TO \(.*\)
MOVE \2 TO \1
You could put the equivalent into an interactive function:
;; untested code follows:
(defun reverse-moves-region (start end)
(interactive "*r")
(goto-char end)
(insert (buffer-substring start end))
(goto-char end)
(while (re-search-forward "MOVE \\(.*\\) TO \\(.*\\)" nil t)
(replace-match "MOVE \\2 TO \\1")))
--
__Pascal_Bourguignon__ http://www.informatimago.com/
----------------------------------------------------------------------
Do not adjust your mind, there is a fault in reality.