help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to convert an arbitrary string into a filename


From: Emanuel Berg
Subject: Re: How to convert an arbitrary string into a filename
Date: Wed, 26 Apr 2023 23:29:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Marcin Borkowski wrote:

> 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?

There are functions to do this to strings, what comes to mind
is `replace-regexp-in-string', but what difference do you mean
there are between filenames and strings that look like filenames?

To me it would be enough downcase all chars, convert chars
with various decorations to their ASCII base equivalents (e.g.
our Swedish å, ä, and ö to a, a, and o - not that one should
use non-English for filenames so a bad example, but sometimes
English has such chars as well), then use the dash char as the
word delimiter, and after that probably just drop remaining
non-alphanumerics.

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]