Re: Strings

From: Hannah Schroeter (hannah_at_schlund.de)
Date: 01/14/04


Date: 14 Jan 2004 20:45:47 GMT

Hello!

Kristof <kristof_jebens@hotmail.com> wrote:

>Can anyone tell me how to convert e.g. a list into a string like the
>print function in lisp does?

There are functions print-to-string, prin1-to-string and
princ-to-string. Or you can use string output streams. In this case,
you can format to the string stream or build the output with multiple
output function calls.

(with-output-to-string (stream)
  (format stream "Hello world! ")
  (princ '(1 2 3) stream))

 =>
"Hello world! (1 2 3)"

>Is there a way to add characters/strings to a string?

It depends. In principle strings are one-dimensional arrays
containing characters. Arrays can be adjustable or not
(i.e. you can change the size of the dimensions), and
have a fill-pointer (a concept that only a part of a one-dimensional
array is really "valid").

So if the string is adjustable, you can destructively append to it
(change the original string).

You can, of course, also do it in a functional way, creating a
new string which is the concatenation of two or more old ones,
using (concatenate 'string a-string another-string)

>Thank you
>Kristof

Kind regards,

Hannah.



Relevant Pages

  • Re: New To Smalltalk. Date format.
    ... it" from a workspace to see the value of the Date object. ... String answered by Date now shows as ... Set the format back by using ... Aside - a Stream is just a Smalltalk class that allows you to store ...
    (comp.lang.smalltalk.dolphin)
  • Re: Question about design, defmacro, macrolet, and &environment
    ... "Expects to find the literal string on the stream." ... (defun send (string &optional stream) ... (declaim (inline make-adjustable-string)) ...
    (comp.lang.lisp)
  • Re: Strange problem when not in debugger
    ... private string huidigWeb; ... int buffLength = 2048; ... // Opens a file stream to read the file to be uploaded ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ReplacerStream
    ... string, do a replace on that string and create a stream again to be ... If those are problems, and you are looking just for a single string, it seems to me that you could just read the stream one character at a time, checking to see if it matches the current character in your search string. ...
    (microsoft.public.dotnet.framework)
  • Re: Strange problem when not in debugger
    ... private string huidigWeb; ... int buffLength = 2048; ... // Opens a file stream to read the file to be uploaded ...
    (microsoft.public.dotnet.languages.csharp)