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 #144 ecu Ignition Coil 2017-09-25 19:19
Does your site have a contact page? I'm having a tough time locating it but, I'd like tto send you an e-mail.
I've got some creative ideas for youur bloog you
might bbe interested in hearing. Either way, great site and I look forward to seeing it grow over time.
Quote
 
 
0 #143 Kids Leather Gear 2017-08-10 18:39
This post is worth everyone's attention. When can I find out more?


my website :: Kids Leather
Gear: http://Www.5Ijjh.cn/space.php?uid=15487&do=blog&id=45255
Quote
 
 
0 #142 Leather Clothing 2017-08-07 21:54
Wow, amazing blog structure! How lengthy have you been blogging for?
you made running a blog look easy. The whole glance of your site is fantastic, as well as the content!


my web blog - Leather Clothing: http://www.Dqhty.com/comment/html/Index.php?page=1&id=53353
Quote
 
 
0 #141 Skinny Jeans 2017-07-25 06:00
We absolutely love your blog and find almost all
of your post's to be just what I'm looking for.
can you offer guest writers to write content for you personally?
I wouldn't mind publishing a post or elaborating on some of the subjects you write about here.
Again, awesome blog!

My homepage: Skinny Jeans: http://www.5Ijjh.cn/space.php?uid=118842&do=blog&id=907875
Quote
 
 
0 #140 gay Leather 2017-07-13 22:08
I'm not sure why but this site is loading extremely slow for me.
Is anyone else having this issue or is it a problem on my end?
I'll check back later on and see if the problem still exists.


Also visit my page :: gay Leather: http://5Ijjh.cn/space.php?uid=13595&do=blog&id=220433
Quote
 
 
0 #139 rom 2017-07-09 01:22
eⲭcellent submit, very infoгmative. I ponder why the other experts of
this sectоr don't noticе this. You must proceed your ѡriting.

I am sure, you haᴠe a һuge readers' base already!


My blog post rom: http://www.gsmlover.com
Quote
 
 
0 #138 shop 2017-07-07 17:22
I don't even know how I ended up here, but I thought this post was good.
I don't know who you are but certainly you are going to a famous blogger
if you are not already ;) Cheers!

Also visit my webpage: shop: http://Www.5Ijjh.cn/space.php?uid=48941&do=blog&id=150506
Quote
 
 
0 #137 Jurand Niedziela 2017-07-07 05:14
Great blog here! Also your site loads up very fast!
What web host are you using? Can I get your affiliate link
to your host? I wish my web site loaded up as fast as yours lol
Quote
 
 
0 #136 Paul Orzel 2017-07-07 02:09
Ridiculous quest there. What occurred after? Take care!
Quote
 
 
0 #135 Martin Stepniewski 2017-07-06 19:55
I want to to thank you for this wonderful read!!
I definitely loved every little bit of it. I have you bookmarked to look at new stuff
you post…
Quote
 

Add comment


Security code
Refresh