{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

LECTURE_9_CS113_2010 - CSC 113 Lecture 9 Strings Strings A...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 113 Lecture 9 Strings
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Strings A string is an array of characters – s = 'abc' is equivalent to s = [ 'a' 'b' 'c' ] All operations that apply to vectors and arrays can be used together with strings as well – s(1) 'a' – s( [ 1 2 ] ) = 'XX' s = 'XXc' – s(end) 'c'
Image of page 2
String Conversion Conversion of strings to numerical arrays – double ( 'abc xyz' ) ans = 97 98 99 32 120 121 122 – double ( 'ABC XYZ' ) ans = 65 66 67 32 88 89 90 Conversion of numerical arrays to strings – char ( [ 72 101 108 108 111 33 ] ) ans = Hello!
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
String Tests ischar() : returns 1 for a character array ischar ( 'CS 113' ) ans = 1 isletter() : returns 1 for letters of the alphabet isletter( 'CS 113' ) ans = 1 1 0 0 0 0 isspace() : returns 1 for whitespace (blank, tab, new line) isspace( 'CS 113' ) ans = 0 0 1 0 0 0
Image of page 4
String Comparison Comparing two characters – 'a' < 'e' ans = 1 Comparing two strings character by character – 'fate' == 'cake' ans = 0 1 0 1 – 'fate' > 'cake' ans = 1 0 1 0
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
String Comparison strcmp() : returns 1 if two strings are identical – a = 'Bilkent'; – strcmp( a, 'Bilkent' ) ans = 1
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern