all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* String variable composed of a repeat character
@ 2021-05-08  7:53 pauline-galea
  2021-05-08 14:20 ` Tassilo Horn
  2021-05-08 14:30 ` [External] : " Drew Adams
  0 siblings, 2 replies; 4+ messages in thread
From: pauline-galea @ 2021-05-08  7:53 UTC (permalink / raw)
  To: Help Gnu Emacs


How can a construct a string variable composed of repeating a character n times?






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: String variable composed of a repeat character
  2021-05-08  7:53 String variable composed of a repeat character pauline-galea
@ 2021-05-08 14:20 ` Tassilo Horn
  2021-05-08 22:06   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-05-08 14:30 ` [External] : " Drew Adams
  1 sibling, 1 reply; 4+ messages in thread
From: Tassilo Horn @ 2021-05-08 14:20 UTC (permalink / raw)
  To: help-gnu-emacs

pauline-galea@gmx.com writes:

> How can a construct a string variable composed of repeating a
> character n times?

One way to do it (which works for both repeating a character or a
string):

--8<---------------cut here---------------start------------->8---
(defun foo/repeat-string (n str)
  (with-temp-buffer
    (dotimes (_ n)
      (insert str))
    (buffer-string)))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [External] : String variable composed of a repeat character
  2021-05-08  7:53 String variable composed of a repeat character pauline-galea
  2021-05-08 14:20 ` Tassilo Horn
@ 2021-05-08 14:30 ` Drew Adams
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2021-05-08 14:30 UTC (permalink / raw)
  To: pauline-galea@gmx.com, Help Gnu Emacs

> How can a construct a string variable composed
> of repeating a character n times?

;; Set MY-VAR to a string of 314 x's.
(setq my-var  (make-string 314 ?x))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: String variable composed of a repeat character
  2021-05-08 14:20 ` Tassilo Horn
@ 2021-05-08 22:06   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-08 22:06 UTC (permalink / raw)
  To: help-gnu-emacs

Tassilo Horn wrote:

>> How can a construct a string variable composed of repeating
>> a character n times?
>
> One way to do it (which works for both repeating a character
> or a string):
>
> (defun foo/repeat-string (n str)
>   (with-temp-buffer
>     (dotimes (_ n)
>       (insert str))
>     (buffer-string)))

Pretty, but there is an easier way and you know it :)

  (make-string 3 ?w) ; www

But what don't you do to get char/string transparency...

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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-08 22:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-08  7:53 String variable composed of a repeat character pauline-galea
2021-05-08 14:20 ` Tassilo Horn
2021-05-08 22:06   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-08 14:30 ` [External] : " Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.