10.2 Declaring Strings


10.2 Declaring Strings

String variables are of type string and can be declared with or without their values, in a similar manner to the variables of primitive types. The following declares a string variable, message.

       string message 

A value of type string is a string constant enclosed in quotes. For example, the following statement assigns a string value to the string variable message.

       set message = "Hello, world!" 

A string variable can be declared with a value; the following declares string variable s2 with the string constant "Hi, everyone!".

       string s2 = "Hi, everyone" 

The two string variables just declared can be displayed on the console with the following statements:

       display message       display s2 

When executing the program that includes these two statements, the following message will appear on the screen:

       Hello, world!       Hi, everyone 




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net