CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.

Slides:



Advertisements
Similar presentations
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
Advertisements

C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
 2003 Prentice Hall, Inc. All rights reserved Fundamentals of Characters and Strings Character constant –Integer value represented as character.
Strings.
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Character String Manipulation. Overview Character string functions sscanf() function snprintf() function.
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Strings CS240 Dick Steflik. What is a string A null terminated array of characters: char thisIsAString[10]; \0 The “\0” (null character)
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Chapter 9 Strings Instructor: Alkar / Demirer. Copyright ©2004 Pearson Addison-Wesley. All rights reserved.9-2 Strings stringC implements the string data.
Chapter 7. Even in quantitative sciences, we often encounter letters and/or words that must be processed by code You may want to write code that: Reads.
 Basically, it’s a sequence of characters.  Character? › Like… a letter. › Or a number. › Or even blank space (like spaces tabs and newlines).
String Functions. Getting Numeric Equivalents of Chars >> double('abc xyz') ans = >> double('ABC XYZ') ans =
Chapter 8 Characters and Strings Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Additional Data Types: 2-D Arrays, Logical Arrays, Strings Selim Aksoy Bilkent University Department of Computer Engineering
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 8 - Characters and Strings Outline 8.1Introduction.
MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering
CS Nov 2006 C-strings.
Additional Data Types: Strings Selim Aksoy Bilkent University Department of Computer Engineering
MATLAB Strings Selim Aksoy Bilkent University Department of Computer Engineering
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
AN ENGINEER’S GUIDE TO MATLAB
Strings in C. Strings are Character Arrays Strings in C are simply arrays of characters. – Example:char s [10]; This is a ten (10) element array that.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Text Processing. Outline Announcements: –Homework I: due Today. by 5, by Discuss on Friday. –Homework II: on web HW I: question 7 Finish functions.
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
February 14, 2005 Characters, Strings and the String Class.
CSE123 Lecture 6 String Arrays. Character Strings In Matlab, text is referred to as character strings. String Construction Character strings in Matlab.
Operators, Functions and Modules1 Pattern Matching & Recursion.
COMP 116: Introduction to Scientific Programming Lecture 24: Strings in MATLAB.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Examples of comparing strings. “ABC” = “ABC”? yes “ABC” = “ ABC”? No! note the space up front “ABC” = “abc” ? No! Totally different letters “ABC” = “ABCD”?
Regular Expressions What is this line all about? while (!($search =~ /^\s*$/)) { It’s a string search just like before, but with a huge twist – regular.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
David Notkin Autumn 2009 CSE303 Lecture 17 #preprocessor Debugging is twice as hard as writing the code in the first place. Therefore, if you write the.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
Chapter 8 Strings. Copyright ©2004 Pearson Addison-Wesley. All rights reserved.9-2 Strings stringC implements the string data structure using arrays of.
Week 3 - Friday.  What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
 2003 Prentice Hall, Inc. All rights reserved. 11 Fundamentals of Characters and Strings Character constant –Integer value of a character –Single quotes.
String Array (Multidimensional Arrays) 1. A string array is a multidimensional array of strings. It is declared in the following syntax: char variable_name[No_of_strings][size_of_each_string];
An Array Type For Strings. Two ways to represent strings – i.e. “Hello” cstring An array with base type char Older way of processing strings Null character.
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
1. Comparing Strings 2. Converting strings/numbers 3. Additional String Functions Strings Built-In Functions 1.
C++ Programming Lecture 19 Strings The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Characters and Strings Functions.
Strings Characters and Sentences 1.Overview 2.Creating Strings 3.Slicing Strings 4.Searching for substrings 1.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 5 : September 4.
ECE 103 Engineering Programming Chapter 29 C Strings, Part 2 Herbert G. Mayer, PSU CS Status 7/30/2014 Initial content copied verbatim from ECE 103 material.
Characters and Text You can assign text strings to MATLAB variables using single quotes. For example, c = 'Hello'; The result is not a numeric matrix or.
Input/Output Functions. 2 MATLAB Basics: Data Files save filename var1 var2 … save homework.mat x y  binary save x.dat x – ascii  ascii load filename.
C Characters and Strings
Chapter 8 - Characters and Strings
Characters and Text You can assign text strings to MATLAB variables using single quotes. For example, c = 'Hello'; The result is not a numeric matrix or.
String Manipulation Chapter 7 Attaway MATLAB 4E.
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Text Manipulation Chapter 7 Attaway MATLAB 5E.
C Characters and Strings
CS 1054 Introduction to Programming in Java
Unit-2 Objects and Classes
Presentation transcript:

CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

Data types So far we have seen the following data types: Double Char String Other?

The class function What is a class? A class is the blueprint from which individual objects are created. Ex. >> x = 14 x = 14 >> class(x) ans = double

Numbers

What’s the min? What’s the max? >> intmax('int32') ans = >> intmin('int32') ans = >> realmax('single') ans = e+038 >> realmin('single') ans = e-038

Changing types From int to double>> y = x y = 10 >> class(y) ans = Int8 >> y = double(y) y = 10 >> class(y) ans = double

More changes >> int8(9.4) ans = 9 >> int8(-9.4) ans = -9 >> int8(-9.5) ans = -10 >> int8(128) ans = 127 >> int8(-1000) ans = -128

Ascii characters

Strings and functions >> book_title = 'Matlab for Smarties‘ >> length(book_title) >> book_title(1) >> book_title(4:16) >> double(book_title) >> s = 'Two is company, three a crowd.'; >> ssub = s(13:end) >> a = 'Three, two, one'; b = ', '; c = 'BLASTOFF!'; >> count_down = [a,b,c]

More string functions >> x = pi; >> fprintf('x:\nto three decimal places: %6.3f\n', x); x: to three decimal places: >> s=sprintf('x:\nto three decimal places: %6.3f\n', x); >> s

Even more… functions char converts type to char findstr finds the positions of a substring in a string (see also strfind) ischar returns 1 if argument is a character array and 0 otherwise isletter finds letters in string isspace finds spaces, newlines, and tabs in string isstrprop finds characters of specified type in string num2str converts number to string length determines the number of characters in string lower converts letters in string to lower case

Even more… functions regexp finds substrings defined by a regular expression sprintf writes formatted data to string (cf. fprintf) strcat concatenates strings strmatch search array for rows that begin with specified string strncmp applies strcmp to the first n characters of strings strcmp returns 1 if two strings are equal and 0 otherwise strcmpi like strcmp but independent of case strncmp compares first n characters of strings strncmpi like strncmp but independent of case str2num converts string to number upper converts string to upper case

QUESTIONS??