114: Data Types: Strings Part 1.

Take Up Code - Un pódcast de Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes

Categorías:

You need more than a bunch of numbers and logic to write an application. You need text and working with individual characters isn’t enough either. In some languages, a string is nothing more than an array of chars that ends with a special null value. Other languages give you much more powerful strings that blend into the language seamlessly. And some languages store strings as a linked list of characters. A good string type will behave just like any other data type. You shouldn’t need to treat them any differently. For example, you can add the two numbers five and five to get the value ten. You should be able to add the two strings “pro” and “gram” to get the word “program” and this operation should use the same operator plus that the numbers used. This topic will describe 21 points and be split into three episodes. The first seven points are: What are string literals? How are single and double quotes used? What are escape sequences and why are they needed? Is the string immutable or mutable? Is the string null-terminated or capable of containing binary data? Is the string empty or null? What’s the difference between the length of strings in character count vs. byte count? Listen to the full episode or you can also read the full transcript below. Transcript In some languages, a string is nothing more than an array of chars that ends with a special null value. Other languages give you much more powerful strings that blend into the language seamlessly. And some languages store strings as a linked list of characters. You can refer to episodes 39 and 40 for discussions about arrays and linked lists as collections. A good string type will behave just like any other data type. You shouldn’t need to treat them any differently. For example, you can add the two numbers five and five to get the value ten. You should be able to add the two strings “pro” and “gram” to get the word “program” and this operation should use the same operator plus that the numbers used. For this episode, there’s a lot of things to consider and learn about strings. I tried to come up with a clever way to structure all this but decided to go with just a numbered set of topics instead. After thinking about strings for a while, I came up with 21 points. This is too much for one episode, so the first 7 points will be included here and the rest will be in two additional episodes. #1 What are string literals? When you embed strings in your code, these are string literals. These are strings that are known at compile time. If you need to translate your application so it works with multiple languages, then the translated strings will be held in some kind of string resource file and will not be directly in your code. #2 How are single and double quotes used? This could depend on your language but normally single quotes are used to hold and define a single character while double quotes are used to define a string. Let’s say you have the single character ‘a’. Putting it inside single quotes means the letter ‘a’. If you don’t use any quotes at all, then that means you’re referring to a variable called “a” which could be the name of a variable of any type. If you put the letter a inside double quotes, then that means you want to define a string that just happens to have a single character, the letter ‘a’. The same thing works with numbers. A single digit number in single quotes represents the character of that digit and not the numeric value. You can only have a single character inside single quotes because they define single characters. Putting multiple letters or numbers inside double quotes, defines a string that contains all of those characters. So, the characters 123 in your source code by themselves with no double quotes defines the numeric value one hundred twenty three. And the same characters insid

Visit the podcast's native language site