[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to convert an arbitrary string into a filename
From: |
Marcin Borkowski |
Subject: |
Re: How to convert an arbitrary string into a filename |
Date: |
Wed, 26 Apr 2023 06:42:04 +0200 |
User-agent: |
mu4e 1.1.0; emacs 30.0.50 |
On 2023-04-26, at 06:03, Platon Pronko <platon7pronko@gmail.com> wrote:
> On 2023-04-26 11:55, Marcin Borkowski wrote:
>> Hi all,
>> given an arbitrary string, say "Hello, world!!!", I want to have
>> a filename with all the runs of weird characters (that is,
>> non-alphanumeric ones) converted to dashes (say, "Hello-world"). Is
>> there a function for that in Emacs already or should I write my own?
>
> Something like this?
>
> (let ((input "Hello, world!!!"))
> (replace-regexp-in-string "[^a-zA-Z0-9]+" "-" input))
> ;; "Hello-world-"
More or less, possibly with trimming - I know it's simple, I just didn't
want to do it if it already exists. Which I still don't know... (I
suppose not, but I'm not sure.)
Thanks,
--
Marcin Borkowski
http://mbork.pl
Re: How to convert an arbitrary string into a filename, Marcin Borkowski, 2023/04/26