Print

Swift Tutorial: Introduction 09 - Variables: Characters

Written by Paul Napier on . Posted in Swift Tutorials: Introduction

Hello everyone and welcome to the ninth tutorial in programming with swift brought to you by MadApper. My name is Paul Napier and in this session we will be covering characters.


Characters in programming are another of the basic types. They are a unit of information which have a graphical representation such as a letter, number or punctuation. In Swift you can create a character variable by declaring the type as a Character, then setting the value inside a set of parentheses. i.e.

var char:Character = "a"

Notice, however, that when declaring a character, the value cannot be longer than a single letter. 

Another set of characters for you to be aware of are string literals. There are several ones you will come across regularly:

\0 (null character),

\\ (backslash),

\t (horizontal tab),

\n (line feed),

\r (carriage return),

\" (double quote) and

\' (single quote).

You are also able to create string literal characters by declaring their Unicode values. Unicode is an encoding format that is used to represent characters across the world's computers. In order to do this, you can follow the same process as before, but instead of writing the character, you can write a \x followed by a 2 digit hexadecimal number or a \U followed by either a 4 or an 8 digit hexadecimal number representing the character you want.

Although you may not require this technique often, it is still useful to understand that this is how the computer recognises characters and that the capital and lowercase versions of a letter are actually seen as different by the device. So for example the letter A would be \U00000041 where as the lowercase version would be \U00000061.

Another instance where this is useful is for non standard characters, such as glyphs. So a star will be \U00002605 and a hammer and sickle is \U0000262D. Or you may wish to represent alternative alphabets and writing systems such as Arabic, Cyrillic or Chinese.

If you need further examples of characters and their Unicode values there are lots of useful resources on the web. However, one of the best tools is unicode-table.com.

Ok! That's covered off the basics of characters. In the next session we are going to build upon this concept and start talking about strings. 

Comments   

 
0 #104 E.oracleclinic.Com 2017-06-28 13:47
Keep on writing, great job!

Feel free to visit my web blog E.oracleclinic.Com: http://E.oracleclinic.com/index.php?mid=board_EOBx93&document_srl=580798
Quote
 
 
0 #103 haircut 2017-06-25 05:24
Expenses - Opening a sаlpn just isn't a shot that could Ьee undrtaken ⲟver a eaցer Ьudget.
Another appointment is needeԁ for just about any haircut: https://www.wildcardhaircuts.com, cοⅼoг, or highlight
services needed. Hаirspray can keep уour hair under сontrol during
bouts of humidity and ⲣrotect it from your UV rayѕ in the sun.
Quote
 
 
0 #102 Gracjan Pawlikowski 2017-06-14 05:42
I'm impressed, I must say. Seldom do I come across
a blog that's both equally educative and entertaining, and without a
doubt, you've hit the nail on the head. The issue is something that not enough folks are speaking intelligently about.
I'm very happy I stumbled across this during my search for something
concerning this.
Quote
 
 
0 #101 Ronald Cichecki 2017-06-13 13:53
My spouse and I stumbled over here by a different website
and thought I might as well check things
out. I like what I see so i am just following you.
Look forward to exploring your web page again.
Quote
 
 
0 #100 Adam Gren 2017-06-13 11:47
Fine way of telling, and good piece of writing to take facts on the topic of
my presentation subject, which i am going to convey in institution of higher education.
Quote
 
 
0 #99 Pawel Konarski 2017-06-12 01:55
What's up Dear, are you actually visiting this site daily, if so then you
will without doubt take pleasant know-how.
Quote
 
 
0 #98 Cyprian Kowalewski 2017-06-11 04:58
I am regular reader, how are you everybody? This piece
of writing posted at this web site is really good.
Quote
 
 
0 #97 Oktawian Makarewicz 2017-06-10 13:48
Greetings! Very useful advice in this particular post!
It's the little changes that produce the biggest changes.
Many thanks for sharing!
Quote
 
 
0 #96 Dymitr Mikolajewski 2017-06-10 10:44
Wow, wonderful blog layout! How long have you been blogging for?

you made blogging look easy. The overall look of your website is excellent, let alone the content!
Quote
 
 
0 #95 Fryderyk Martyniak 2017-06-10 07:07
Very soon this site will be famous among all blog
people, due to it's fastidious posts
Quote
 

Add comment


Security code
Refresh