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

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

Re: Getting substring


From: Pierre Rouleau
Subject: Re: Getting substring
Date: Wed, 16 Aug 2023 23:01:52 -0400

> > Why does the following not print the first word?
> > >
> > > > (message "%s TEST: " (car (split-string grafm)))
> > >
> > > Are you sure it does not print it? It prints bigoplus for me.
> > > You can also look into the 'Message' buffer to see what was printed by
> > > the message function. - Pierre
>
> I now realise my mistake of putting "%s" before "TEST".  I was thus doing
> things
> correctly after all.
>
> The command (car (split-string grafm)) also works if there are no spaces in
> 'grafm', it still returns the string as a first element in the list result.
>
> Not sure I follow you...
- You do understand that message is just a string formatting function that
takes arguments to put in places identified by the '%s', right?
- And that format does something similar but just returns the formatted
string.
- therefore you can use ielm to test your code (use it!):

Here's a session:

ELISP> (setq str "bigoplus ⨁︁")
"bigoplus ⨁︁"
ELISP> (car (split-string str))
"bigoplus"
ELISP> (format " 123-- %s -- " (car (split-string str)))
" 123-- bigoplus -- "
ELISP> (format "%s TEST" (car (split-string str)))
"bigoplus TEST"
ELISP> (format "Survey says: %s " (car (split-string str)))
"Survey says: bigoplus "
ELISP>









-- 
/Pierre


reply via email to

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