Text functions.

Slides:



Advertisements
Similar presentations
COMP 116: Introduction to Scientific Programming Lecture 37: Final Review.
Advertisements

LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
1. Write an Excel text function in cell Company Data!A4, which may be copied down, to string together the first and last name with only the first letter.
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Lecture 09 Strings, IDEs. METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan Mon July 29, 2002.
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 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.
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
Lecture 3 Sept 3 Complete Chapter 3 Exercises quiz.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
ES 100: Lecture 7 String Functions 1.Log in 2.Open MATLAB 3.Change the current directory and path to U: 4.Change the numeric display to compact (File,
Lecture 3 August 31 Chapter 3. Chapter 3 – numbers, string, booleans integer: MATLAB stores numeric data as double-precision floating point (double) by.
CS Nov 2006 C-strings.
Fall 2006AE6382 Design Computing1 Matlab File & Directory Management Learning Objectives Define file input and output terminology Compare high and low.
Insight Through Computing 15. Strings Operations Subscripting Concatenation Search Numeric-String Conversions Built-Ins: int2str,num2str, str2double.
Covenant College September 3, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 6: Character Strings.
AN ENGINEER’S GUIDE TO MATLAB
Text Processing. Outline Announcements: –Homework I: due Today. by 5, by Discuss on Friday. –Homework II: on web HW I: question 7 Finish functions.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
Fall 2006AE6382 Design Computing1 Cell Arrays and Structures Learning Objectives Learn about characters, cell arrays & structures Topics Data Types Character.
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
EGR 2261 Unit 9 Strings and C-Strings  Read Malik, pages in Chapter 7, and pages in Chapter 8.  Homework #9 and Lab #9 due next week.
COMP 116: Introduction to Scientific Programming Lecture 24: Strings in MATLAB.
C++ PROGRAMMING: PROGRAM DESIGN INCLUDING DATA STRUCTURES, FIFTH EDITION Chapter 10: Strings and string type.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Arrays and Strings. Why? Consider a class of 30 students, each has a score for hw1  Do we want to have 30 variables with different names?  Would it.
PROCESSING Types. Objectives Be able to convert between binary and decimal numbers. Be able to declare and initialize character variables and constants.
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
Representing Strings and String I/O. Introduction A string is a sequence of characters and is treated as a single data item. A string constant, also termed.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Matlab Basic. MATLAB Product Family 2 3 Entering & Quitting MATLAB To enter MATLAB double click on the MATLAB icon. To Leave MATLAB Simply type quit.
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.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
1 CSE 2337 Chapter 7 Organizing Data. 2 Overview Import unstructured data Concatenation Parse Create Excel Lists.
Using and Programming with MATLAB as an Engineering Tool [ Part III ]
Strings Characters and Sentences 1.Overview 2.Creating Strings 3.Slicing Strings 4.Searching for substrings 1.
1 Arrays and Pointers The name of an array is a pointer constant to the first element. Because the array’s name is a pointer constant, its value cannot.
Lecture 6: More Decisions & Arrays B Burlingame 9 March 2016.
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.
An Introduction to Programming in Matlab Emily Blumenthal
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 in C++. 2 Using Strings in C++ Programs String library or provides functions to: - manipulate strings - compare strings - search strings ASCII.
1 Chapter 8 – Character Arrays and Strings Outline 8.1Introduction 8.2Declaring and Initializing String 8.3Input/output of strings 8.4String-handling Functions.
Working with files Saving and loading Matlab variables to and from .mat files does not require any special file handling, just use save() and load() However,
Computer Programming ||
INC 161 , CPE 100 Computer Programming
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
Physics 114: Final Project Hints
A First Book of ANSI C Fourth Edition
Module 2 Arrays and strings – example programs.
Functions (subprograms)
Strings A string is a sequence of characters treated as a group
CS111 Computer Programming
Advanced Data Import & Export Jeff Henrikson
Object Oriented Programming COP3330 / CGS5409
C Stuff CS 2308.
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.
Week 9 – Lesson 1 Arrays – Character Strings
String Manipulation Chapter 7 Attaway MATLAB 4E.
Text Processing.
Chapter 8 Data Structures: Cell Arrays and Structures
String in C++.
funCTIONs and Data Import/Export
Chapter 8 Character Arrays and Strings
Topics discussed in this section:
Text Manipulation Chapter 7 Attaway MATLAB 5E.
Chapter 8 Data Structures: Cell Arrays and Structures, Sorting
cout << str1;  pear
Presentation transcript:

Text functions

char vs. string Matlab has a new string class, that you are discouraged from using for this course. You can create a string object using double-quotes. e.g., s="apple" We will only discuss char vectors. You can create a char vector using single-quotes. e.g. s='apple'

ASCII Table

Matlab Text: one character ~ one number >> double('hello') ans = 104 101 108 108 111 >> %newline is not a new row in the matrix >> char([104 101 108 10 108 111 ]) hel lo >> %two '' encodes a single ' in a string >> msg='ahmet''s presentation' msg = ahmet's presentation

Text functions >> ischar('Hello 123') 1 >> lower('Hello 123') hello 123 >> upper('Hello 123') HELLO 123 >> isletter('Hello 123') 1 1 1 1 1 0 0 0 0 >> isspace('Hello 123') 0 0 0 0 0 1 0 0 0

Multiple texts Use cell arrays when you need to store multiple texts in a variable. You would typically need to a vector of texts, but a matrix of texts (e.g., when you load data from an Excel file) is also possible. >> msgs={'hello','yes','no'} msgs = 'hello' 'yes' 'no’ >> msgs={'hello','world';'yes','no'} 'hello' 'world' 'yes' 'no'

strjoin(): Join Multiple Texts >> % join using a space character >> strjoin( {'apple', 'orange', 'cherry'} ) ans = 'apple orange cherry' >> % join with a custom character/text >> strjoin( {'apple', 'orange', 'cherry'}, ',') 'apple,orange,cherry' >> strjoin( {'apple', 'orange', 'cherry'}, ' and ') 'apple and orange and cherry'

Concatenating Texts >> % Using strjoin() >> names = {'apple', 'orange', 'cherry'} ; >> name=strjoin(names, '') name = 'appleorangecherry' >> % Using vector notation: >> name=[names{1}, names{2}, names{3}] >> name=[ names{1:end} ] >> %Using sprintf() >> name = sprintf( '%s%s', 'apple', 'orange') 'appleorange'

strsplit(): Splitting text into multiple texts strsplit(s,delimiter) strsplit(s,{delimiter1, delimiter2}) strsplit(... ,'CollapseDelimiters',false) >> strsplit('apple,,,orange,cherry', ',') ans = 1×3 cell array {'apple'} {'orange'} {'cherry'} >> strsplit('apple,,,orange,cherry', ',','CollapseDelimiter',false) 1×5 cell array {'apple'} {0×0 char} {0×0 char} {'orange'} {'cherry'}

strtrim(): Trimming blank spaces >> [ '#' strtrim(' ahmet sacan ') '#' ] ans = #ahmet sacan#

strcmp(): Compare Texts strcmp('str1','str2') strcmpi('str1','Str2') strncmp('str1', 'str2', n) strncmpi('str1', 'Str2', n) >> [strcmp('yes','yes'), strcmp('yes','no')] >> strcmp('yes','YES') >> strcmpi('yes','YES') >> strcmp(lower('yes'),lower('YES')) >> strcmp('yes','yes ') >> strcmp('yes’, strtrim('yes '))

strcmp(): Compare with multiple texts strcmp( {'str1','str2'}, 'str2') find(strcmp( {'str1','str2'}, 'str2'))

strfind(): Locate Subtext k=strfind(haystack, needle) >> strfind('Find the starting indices of the pattern string', 'in') 2 15 19 45

Replacing Subtext strrep(haystack, oldneedle, newneedle) >> strrep('flow crow','ow','y')

Conversion from number to text >> sprintf('%.2f %.0f', 7/3, 7/3) ans = '2.33 2'

Conversion to number from text x = str2double( str ) >> str2double( '123.45e7' ) >> str2double( '1,200' )