Programming Class

  • rss
  • Home

Strings

1) Strings

[ Up ] [ Next ]

Computers are sophisticated calculators, and deal exclusively with numbers (digits).  In order to get them to cope with other types of information, we have to encode that information in a numerical (digital) way.  Let’s say that we give every letter of the alphabet a unique number, for example:

1 2 3 4 5 6 7 8 9 10 11 12 13
A B C D E F G H I J K L M
14 15 16 17 18 19 20 21 22 23 24 25 26
N O P Q R S T U V W X Y Z

While we’re at it, we should give all the symbols we would possibly want to use a number:

27 28 29 30 31 32 33 34 35 36
! “ £ $ % ^ & * ( )

And if we want to represent numbers themselves as text rather than their numerical value, we should give each of the numbers a number:

37 38 39 40 41 42 43 44 45 46
0 1 2 3 4 5 6 7 8 9

Letters, symbols, and numbers collectively are known as characters.  A set  deciding which character gets which number is known as a character encoding.  Clearly, if we want to copy and paste text from one program to another, or just send an email, everyone needs to agree on which character encoding to use.  Two of the most popular character encodings are known as ASCII and Unicode.

Characters on their own are not as much use as lists of characters.  When we put characters together side by side we can make words, sentences, or entire books.

8 5 12 12 15 27
H E L L O !

A list of characters is known as a string.  To tell the compiler we want to specify a string, we use a pair of  ” symbols.  Everything between the ” symbols will be encoded by the compiler as a list of characters, for example:

"Hello"

The string must all be on one line however, and we can’t use the ” character inside a string or the compiler will get confused about where the string ends, and the rest of the program begins.

Tasks:

  • Compile and run the program to see what happens
  • Replace the characters inside the “ symbols with your own name, and compile and run again.
Categories
Uncategorized
Comments rss
Comments rss
Trackback
Trackback

« Beginners Why You Should Use Managed Hosting »

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blogroll

  • COD 5
  • Dell Inspiron Chargers
  • Door Handles
  • Kiosks
  • Laptops

Tags

Broadband Managed Hosting mobile broadband solar heating solar lighting Telephone Systems wireless broadband

Categories

  • Broadband
  • Hosting
  • News
  • Telephone Systems
  • Uncategorized

Pages

  • About
  • Access Ramps
  • Automotive Class
    • Driving Training
    • Environmental
  • Business Class
    • Online marketing
    • Website Design
  • Cosmetic Surgery Info
  • Financial Class
  • Health Class
  • Leisure Class
    • Beauty/Spas
  • Oral Care
  • Other Class
  • Promotional Videos
  • Property Class
  • Services Class
    • 08 numbers
    • Roofing
  • Shopping Class
  • Small business phone systems
  • Technology Class
    • Laptops
Content provided by Custard Media