From: Francesco Moi
Subject: How to manipulate quotes (")
Date: 
Message-ID: <5b829932.0112170312.59cb0364@posting.google.com>
Hi again.

I'm interested in determinate if the first two characters of 
a string are quotes:

MyString: """John"

I tried with:
(if (string= "\"\"" (subseq MyString 0 1))

But it does not work. Could anybody provide me any help? Best
regards.

From: hading
Subject: Re: How to manipulate quotes (")
Date: 
Message-ID: <b84a274a.0112170632.422f8cf6@posting.google.com>
(Francesco Moi) wrote 

 
> I'm interested in determinate if the first two characters of 
> a string are quotes:
> 
> MyString: """John"
> 
> I tried with:
> (if (string= "\"\"" (subseq MyString 0 1))
> 
> But it does not work. Could anybody provide me any help? Best
> regards.

Sure.  The subsequence you are taking only has length 1.  You want
(subseq MyString 0 2).  See the documentation of subseq for details.
From: Software Scavenger
Subject: Re: How to manipulate quotes (")
Date: 
Message-ID: <a6789134.0112170635.1b91b35e@posting.google.com>
············@europe.com (Francesco Moi) wrote in message news:<····························@posting.google.com>...

> (if (string= "\"\"" (subseq MyString 0 1))

Always post the symptom explicitly.  Never assume people are going to
take the time to understand what you are complaining about.  They have
other messages to read and not much time before they want to get back
to their gigantic Lisp projects.  In this case the symptom could be
described as "there was no error message but the if form executed its
else form instead of its then form."

In any case, your bug is in the way you use subseq:

From the Hyperspec:

subseq creates a sequence that is a copy of the subsequence of
sequence bounded by start and end.

Start specifies an offset into the original sequence and marks the
beginning position of the subsequence.
end marks the position following the last element of the subsequence.
From: Kent M Pitman
Subject: Re: How to manipulate quotes (")
Date: 
Message-ID: <sfwg066aldi.fsf@shell01.TheWorld.com>
············@europe.com (Francesco Moi) writes:

> Hi again.
> 
> I'm interested in determinate if the first two characters of 
> a string are quotes:
> 
> MyString: """John"
> 
> I tried with:
> (if (string= "\"\"" (subseq MyString 0 1))
> 
> But it does not work. Could anybody provide me any help? Best
> regards.

Don't use subseq, which will cons.

(string-equal my-string "\"\""
              :end1 (min (length my-string) 2))

I claim it's a bug in implementations that don't allow you to say

(string-equal my-string "\"\"" :end1 2)

but some insist on blowing up if my-string is very short.  That
seems dumb to me because there ends up never being a case where
(min (length my-string) ...value I really want...) isn't required,
and STRING-EQUAL will already have to redundantly test that anyway,
so it's an utter waste.  But I know some implementations do gratuitously
blow up on this, so be careful.
From: Dr. Edmund Weitz
Subject: Re: How to manipulate quotes (")
Date: 
Message-ID: <m3heqmkfz0.fsf@bird.agharta.de>
············@europe.com (Francesco Moi) writes:

> Hi again.
> 
> I'm interested in determinate if the first two characters of 
> a string are quotes:
> 
> MyString: """John"
> 
> I tried with:
> (if (string= "\"\"" (subseq MyString 0 1))
> 
> But it does not work. Could anybody provide me any help? Best
> regards.

Should work if you replace the 1 with 2:

  * (defparameter *my-string* "\"\"Foo")
  
  *MY-STRING*
  * *my-string*
  
  "\"\"Foo"
  * (subseq *my-string* 0 2)
  
  "\"\""
  * (string= "\"\"" (subseq *my-string* 0 2))
  
  T
  * (string= "\"\"" (subseq *my-string* 0 1))
  
  NIL
  
Edi.
From: Thomas A. Russ
Subject: Re: How to manipulate quotes (")
Date: 
Message-ID: <ymig066brhl.fsf@sevak.isi.edu>
············@europe.com (Francesco Moi) writes:

> 
> I'm interested in determinate if the first two characters of 
> a string are quotes:
> 
> MyString: """John"
> 
> I tried with:
> (if (string= "\"\"" (subseq MyString 0 1))
> 
> But it does not work. Could anybody provide me any help? Best
> regards.

The previous poster provided the specific solution.

The more general solution is to take advantage of the interactive nature
of the Lisp development environment and look at the function results.
For example, if you had typed 

  (subseq MyString 0 1)

in the Lisp listener (the Lisp top level), then you would have see the
return value

  "\""

which might have given you the clue that the subsequence being returned
was not the one you expected.

This ability to easily try out subforms of Lisp expressions is one of
the development benefits of the Lisp programming environment.  You can
exploit it to speed up the process of testing and debugging your code.



-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu