From: uzibalqa <uzibalqa@proton.me>
To: uzibalqa <uzibalqa@proton.me>
Cc: uzibalqa via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org>
Subject: Re: Swapping characters in a word inside elisp code
Date: Fri, 28 Jul 2023 19:44:02 +0000 [thread overview]
Message-ID: <P8k4C4w7ifMhsd5hTk6x5tJ29kmPXSCBgSerUJhK3-6RDpqKPKDnb4xHXYWhw9f7Bcu2bANKEDO2VVETJLA3tNO4C6PbsHLUuEKcBhXM-J8=@proton.me> (raw)
In-Reply-To: <t8xtMSNdMSt4SS51xuToeFTDPK9Otl_4cpOuFuTmQgemzDAVgYuIc8UIAloJ-VvJAo56oo-cODBu4jeEZYayLHkw18AUitQdGV4nhRBa1mo=@proton.me>
Sent with Proton Mail secure email.
------- Original Message -------
On Saturday, July 29th, 2023 at 6:03 AM, uzibalqa <uzibalqa@proton.me> wrote:
> I have a word and want to swap characters at position i with position j.
>
> What would be a good way to do this ? Would I need to change structure
> (to array, vector or some other thing) ?
I have done it this way, but it fails when p > q
How can I solve this ?
(defun cswap (wstr p q)
"Replace characters in WSTR at positions P and Q."
(let ( (char1 (elt wstr p))
(char2 (elt wstr q)) )
(if (and char1 char2)
(concat (substring wstr 0 p)
(char-to-string char2)
(substring wstr (+ p 1) q)
(char-to-string char1)
(substring wstr (+ q 1)))) ))
next prev parent reply other threads:[~2023-07-28 19:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 18:03 Swapping characters in a word inside elisp code uzibalqa
2023-07-28 19:44 ` uzibalqa [this message]
2023-07-28 20:45 ` Marcin Borkowski
2023-07-28 20:32 ` [External] : " Drew Adams
2023-07-28 20:45 ` uzibalqa
2023-07-28 20:48 ` uzibalqa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='P8k4C4w7ifMhsd5hTk6x5tJ29kmPXSCBgSerUJhK3-6RDpqKPKDnb4xHXYWhw9f7Bcu2bANKEDO2VVETJLA3tNO4C6PbsHLUuEKcBhXM-J8=@proton.me' \
--to=uzibalqa@proton.me \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).