comp.lang.ada
 help / color / mirror / Atom feed
* Re: newbie question: the " character inside a string
  2000-05-24  0:00 newbie question: the " character inside a string Martin Tobisch
  2000-05-24  0:00 ` John English
@ 2000-05-24  0:00 ` Robert Dewar
  2000-05-24  0:00 ` David C. Hoos, Sr.
  2000-05-24  0:00 ` Ted Dennison
  3 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 2000-05-24  0:00 UTC (permalink / raw)


In article <8ggcnp$83r$1@inf2.informatik.uni-stuttgart.de>,
  "Martin Tobisch" <tobiscmn@rupert.informatik.uni-stuttgart.de>
wrote:
> hello everbody,
>
> i have a simple question :
>
> what do i have to do if i want to include a " inside of a
string?
> for instance make the string: name="something"?
> can i write is as normal "name="something"" an ADA will ignore
> the inner "'s es as string delimiter and only look for the
outest "'s es?
> or do i have to quote the " inside of a string with a special
character?
>
> thanks for any help


You *definitely* need to have access to an Ada text book. This
is a question that will be answered in any text book.
Alternatively you could look this one up in the RM, you will
find the answer in RM 2.6, entitled string literals, and the
answer is very easy to find there.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: newbie question: the " character inside a string
  2000-05-24  0:00 newbie question: the " character inside a string Martin Tobisch
                   ` (2 preceding siblings ...)
  2000-05-24  0:00 ` David C. Hoos, Sr.
@ 2000-05-24  0:00 ` Ted Dennison
  2000-05-24  0:00   ` Robert Dewar
  2000-05-25  0:00   ` Geoff Bull
  3 siblings, 2 replies; 8+ messages in thread
From: Ted Dennison @ 2000-05-24  0:00 UTC (permalink / raw)


In article <8ggcnp$83r$1@inf2.informatik.uni-stuttgart.de>,
  "Martin Tobisch" <tobiscmn@rupert.informatik.uni-stuttgart.de> wrote:

> what do i have to do if i want to include a " inside of a string?

I know you already got a RTFM answer, but most manuals I have seen don't
properly address string handling in Ada (it really ought to have its own
chapter) and the LRM seems like overkill for such a simple question.

There are two simple ways (I know of) to do this:

  1)  Catenate a quotation character to your string eg:

   Value : constant String := "The name is " & '"' &
Some_String_Variable & '"';


  2)  "Escape" the quotation character in the string literal with
another quotation character:

   Value : constant String "= The name is """ & Some_String_Variable &
"""";


If you are using emacs, you'll probably want to stick to method 2, since
method 1 throws off Ada-mode's colorization.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: newbie question: the " character inside a string
  2000-05-24  0:00 ` Ted Dennison
@ 2000-05-24  0:00   ` Robert Dewar
  2000-05-24  0:00     ` Jeff Carter
  2000-05-25  0:00   ` Geoff Bull
  1 sibling, 1 reply; 8+ messages in thread
From: Robert Dewar @ 2000-05-24  0:00 UTC (permalink / raw)


In article <8ggrm2$ein$1@nnrp1.deja.com>,
  Ted Dennison <dennison@telepath.com> wrote:
> In article <8ggcnp$83r$1@inf2.informatik.uni-stuttgart.de>,
>   "Martin Tobisch"
<tobiscmn@rupert.informatik.uni-stuttgart.de> wrote:
>
> > what do i have to do if i want to include a " inside of a
string?
>
> I know you already got a RTFM answer, but most manuals I have
> seen don't properly address string handling in Ada (it really
> ought to have its own chapter)

I disagree, all good Ada text books quite clearly describe how
to write string literals.

> and the LRM seems like overkill
> for such a simple question.

I disagree, first, you can immediately find the section by
looking for string (it is the first occurrence of the word
string in the main body of the RM), and you find the statements:

    4   A string_element is either a pair of quotation marks
        (""), or a single graphic_character other than a
        quotation mark.

and

5   The sequence of characters of a string_literal is formed
from the sequence of string_elements between the bracketing
quotation marks, in the given order, with a string_element that
is "" becoming a single quotation mark in the sequence of
characters, and any other string_element being
reproduced in the sequence.

This is not difficult stuff AT ALL, and people need to be able
to read paragraphs like the above and understand them.

Also the suggestion of using concatenation is way off base,
I strongly disagree with this because it introduces all kinds
of unnecessary semantics into the discussion about bounds and
the operation of concatenation. It is also ugly and has no
possible advantage over the normal "" quoting mechanism.

Learning to read manuals is at least as important to students
as learning Ada. In fact if we really want to be honest, the
ability to read manuals is probably much MORE important than
learning insignificant syntactic details about how to write
string literals in one particular language.

Yes, you can be lazy and get an answer to simple questions on
CLA, but as we very well know, when people have more complex
questions, they either don't get answers, or they get completely
inaccurate answers. The ability to learn for oneself from
reference materials is a vital one.







>
> There are two simple ways (I know of) to do this:
>
>   1)  Catenate a quotation character to your string eg:
>
>    Value : constant String := "The name is " & '"' &
> Some_String_Variable & '"';
>
>   2)  "Escape" the quotation character in the string literal
with
> another quotation character:
>
>    Value : constant String "= The name is """ &
Some_String_Variable &
> """";
>
> If you are using emacs, you'll probably want to stick to
method 2, since
> method 1 throws off Ada-mode's colorization.
>
> --
> T.E.D.
>
> http://www.telepath.com/~dennison/Ted/TED.html
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: newbie question: the " character inside a string
  2000-05-24  0:00   ` Robert Dewar
@ 2000-05-24  0:00     ` Jeff Carter
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Carter @ 2000-05-24  0:00 UTC (permalink / raw)


I tend to use

'"' & "This is in quotes" & '"'

because

1. "" in the middle of a string is ugly

2. It's easier to tell that the string contains '"'

3. People who have forgotten or didn't learn the "" special case don't
have any problem understanding it.

-- 
Jeff Carter
"I unclog my nose towards you."
Monty Python & the Holy Grail




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

* newbie question: the " character inside a string
@ 2000-05-24  0:00 Martin Tobisch
  2000-05-24  0:00 ` John English
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Martin Tobisch @ 2000-05-24  0:00 UTC (permalink / raw)


hello everbody,

i have a simple question :

what do i have to do if i want to include a " inside of a string?
for instance make the string: name="something"?
can i write is as normal "name="something"" an ADA will ignore
the inner "'s es as string delimiter and only look for the outest "'s es?
or do i have to quote the " inside of a string with a special character?

thanks for any help

Greetings MArtin Tobisch







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

* Re: newbie question: the " character inside a string
  2000-05-24  0:00 newbie question: the " character inside a string Martin Tobisch
  2000-05-24  0:00 ` John English
  2000-05-24  0:00 ` Robert Dewar
@ 2000-05-24  0:00 ` David C. Hoos, Sr.
  2000-05-24  0:00 ` Ted Dennison
  3 siblings, 0 replies; 8+ messages in thread
From: David C. Hoos, Sr. @ 2000-05-24  0:00 UTC (permalink / raw)



Martin Tobisch <tobiscmn@rupert.informatik.uni-stuttgart.de> wrote in
message news:8ggcnp$83r$1@inf2.informatik.uni-stuttgart.de...
> hello everbody,
>
> i have a simple question :
>
> what do i have to do if i want to include a " inside of a string?
> for instance make the string: name="something"?
> can i write is as normal "name="something"" an ADA will ignore
> the inner "'s es as string delimiter and only look for the outest "'s es?
> or do i have to quote the " inside of a string with a special character?
>
Here is the relevant section of the Ada Reference Manual:

2.6 String Literals

1 A string_literal is formed by a sequence of graphic characters (possibly
none) enclosed between two quotation marks used as string brackets. They are
used to represent operator_symbols (see 6.1), values of a string type (see
4.2), and array subaggregates (see 4.3.3).

Syntax

2 string_literal ::= "{string_element}"
3 string_element ::= "" | non_quotation_mark_graphic_character

4 A string_element is either a pair of quotation marks (""), or a single
graphic_character other than a quotation mark.

Static Semantics

5 The sequence of characters of a string_literal is formed from the sequence
of string_elements between the bracketing quotation marks, in the given
order, with a string_element that is "" becoming a single quotation mark in
the sequence of characters, and any other string_element being reproduced in
the sequence.
6 A null string literal is a string_literal with no string_elements between
the quotation marks.

NOTES

7 5 An end of line cannot appear in a string_literal.

Examples

8 Examples of string literals:

9 "Message of the day:"

""                           -- a null string literal
" "   "A"   """"             -- three string literals of length 1

"Characters such as $, %, and } are allowed in string literals"


> thanks for any help
>
> Greetings MArtin Tobisch
>
>
>






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

* Re: newbie question: the " character inside a string
  2000-05-24  0:00 newbie question: the " character inside a string Martin Tobisch
@ 2000-05-24  0:00 ` John English
  2000-05-24  0:00 ` Robert Dewar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: John English @ 2000-05-24  0:00 UTC (permalink / raw)


Martin Tobisch wrote:
> what do i have to do if i want to include a " inside of a string?
> for instance make the string: name="something"?

  S : String := "name=""something""";

Use "" for " inside a string.

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: newbie question: the " character inside a string
  2000-05-24  0:00 ` Ted Dennison
  2000-05-24  0:00   ` Robert Dewar
@ 2000-05-25  0:00   ` Geoff Bull
  1 sibling, 0 replies; 8+ messages in thread
From: Geoff Bull @ 2000-05-25  0:00 UTC (permalink / raw)


Ted Dennison wrote:
> the LRM seems like overkill for such a simple question.

Finding the answer to such a simple question is a good way to learn how
to use the RM. As well, the RM is often a quicker source for an answer
because it is not obscured by a lot of explanation. When I don't understand
the RM, I then consult a textbook.




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

end of thread, other threads:[~2000-05-25  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-24  0:00 newbie question: the " character inside a string Martin Tobisch
2000-05-24  0:00 ` John English
2000-05-24  0:00 ` Robert Dewar
2000-05-24  0:00 ` David C. Hoos, Sr.
2000-05-24  0:00 ` Ted Dennison
2000-05-24  0:00   ` Robert Dewar
2000-05-24  0:00     ` Jeff Carter
2000-05-25  0:00   ` Geoff Bull

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox