[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
elisp find/replace efficiency question
From: |
Xah Lee |
Subject: |
elisp find/replace efficiency question |
Date: |
Wed, 08 Dec 2010 15:31:14 -0000 |
User-agent: |
G2/1.0 |
suppose i want write a command that do a find/replace on a region
which is more efficient?
(defun space2underscore-region (p1 p2)
"Replace space by underscore in region."
(interactive "r")
(save-restriction
(narrow-to-region p1 p2)
(goto-char (point-min))
(while (search-forward " " nil t) (replace-match "_")) ) )
vs
...
(setq meat (replace-regexp-in-string " " "_"
(buffer-substring-no-properties p1 p2)) )
(delete-region p1 p2)
(insert meat)
vs
(replace-string " " "_" nil p1 p2)
it appears to me, the first is most efficient but is most cumbersome.
The last is most lean, but least efficient.
(sorry if this is a duplicate post)
Xah ∑ xahlee.org ☄
- elisp find/replace efficiency question,
Xah Lee <=