From the course: Programming Foundations: Discrete Mathematics
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Characters and strings
From the course: Programming Foundations: Discrete Mathematics
Characters and strings
- [Voiceover] Sometimes, it's necessary to use characters and strings when programming. SML has some very specific syntax that should be addressed in case your programs require these data types. To use a character in SML, it must be prefixed with the pound sign, followed by double quotes around the character. Here is an example. Pound sign, double quotes, a double quotes, semicolon, now when I hit enter, it creates a variable i-t, it, and it sets it to the letter a, which is a character. It is important to note that there are no spaces between the pound sign and the first double quote. A string on the other hand, is a sequence of characters and it is defined by simply enclosing it in double quotes. I'm going to go ahead and put double quotes, Peggy, space, Fisher, double quotes, semicolon, and now I've replaced the variable i-t with the string Peggy Fisher. Often times we need to concatenate or combine two strings. In SML we use the caret symbol. The caret symbol is located on the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.