Re: Quoted text?
Re: Quoted text?
- Subject: Re: Quoted text?
- From: "Arthur J Knapp" <email@hidden>
- Date: Thu, 18 Jan 2001 11:21:50 -0500
>
Subject: Quoted text?
>
Date: Wed, 17 Jan 2001 14:28:00 -0500
>
From: Michael Kern <email@hidden>
>
I am having trouble creating a quoted text string. I9m following the
>
example in a book I have.
>
set x to "He said \"Oops.\" after dropping the plate." as string
>
Result:
>
"He said \"Oops.\" after dropping the plate."
>
>
What I want:
>
"He said "Oops." after dropping the plate."
>
(see no slashes)
>
I DO NOT want the back slashes to appear in the string.
>
How do I go about getting the quoted text into the variable?
This is a conceptual problem that many new scripters have. There
is a perception that when a string shows up in the script editor's
result window with backslashes preceding quotes, that there is an
actual backslash character in the string. In fact, for most intents
and purposes, there isn't.
If you run this snippet, you will see that the *user display* value
of a backslash-quote combination simply produces the quote:
display dialog "Michael \"the Man\" Kern"
--> displays: Michael "the Man" Kern
You can also see that the following:
count characters of "abc\"def"
returns 7, not 8, indicating that backslash-quote is counted
as a single character.
Computers need ways of *marking* data such that it can know
where one piece of data ends and another begins. If you look
at what it is that you are asking for:
"He said "Oops." after dropping the plate."
you can see that there is no way for the AppleScript compiler
to determine where the string ends, (it would assume that "He said "
is a string, followed by the meaningless Oops. word)
When you say that you don't want the slashes to appear in the string,
there isn't much you can do about it, as far as your script editor's
result windows go. Rest assured, however, that if you send your string
to a dialog box, set it to a filename, or write it to a text file, you
will only see the quotes.
>
How do I go about getting the quoted text into the variable?
set str to "He said \"Oops.\" after dropping the plate."
set AppleScript's text item delimiters to {"\""}
set MyVariable to text item 2 of str
-- { "He said ", "Oops." , " after dropping the plate." }
-- text item 2
set AppleScript's text item delimiters to {""} -- restore
MyVariable -- > "Oops."
--
{
Arthur J Knapp, of STELLARViSIONs ;
http://www.STELLARViSIONs.com ;
mailto:email@hidden ;
"...well the rain falls down
without my help, I'm afraid
and my lawn gets wet,
though I withheld my consent..."
}