Presentation is loading. Please wait.

Presentation is loading. Please wait.

Anyone recognize this string? GACGGGCTCTGACCCCCTT CGCG List other places where you use strings regularly.

Similar presentations


Presentation on theme: "Anyone recognize this string? GACGGGCTCTGACCCCCTT CGCG List other places where you use strings regularly."— Presentation transcript:

1

2 Anyone recognize this string? GACGGGCTCTGACCCCCTT CGCG List other places where you use strings regularly.

3 A string (text) is made up of keyboard (and other) possible symbols.

4 Most programming languages support String data. We are going to examine a relatively standard string notation, that works in the following languages: Perl Python Javascript CAUTION: Syntax matters in these languages!

5 A literal is enclosed within "…" Any string can be assigned to one or more variable(s). "The quick brown fox jumps over a lazy dog." "Computational Thinking" "University of Wisconsin – La Crosse" gettysburg = "Four score and seven years ago... "; lyric1 = "We are in the crowd, we’re c-comin’ out"; bestActor = "Jack Nicholson"; Syntax: variable = stringExpression;

6 Two strings can be joined (concatenated) using + legalAssoc = "para" + "legal"; combined = "social" + " media " + "website"; street = "1600 Pennsylvania Ave."; city = "Washington, DC"; zip = "20006”; space = " "; address = street + space + city + " " + zip;

7 Every string has a length – the count of its characters. gettysburg = "Four score and seven years ago... "; lyric1 = "We are in the crowd, we’re c-comin’ out"; bestActor = "Jack Nicholson"; bestActor.length is14 lyric1.length is39 gettysburg.length is35

8 Every string consists of a sequence of characters that are numbered by position.  Each position has an integer index.  The first (leftmost) position is zero (0). groundBeef = "hamburger"; hamburger 012345678

9 The following is a formula to retrieve a single character from a string: strExpr [index] where strExpr is any valid string expression and index is an integer expression with value in the range from 0 through strExpr.length. groundBeef = "hamburger"; hamburger 012345678 oneLetter = groundBeef[6]; curious = groundBeef[0] + groundBeef[2] + groundBeef[2]; parent = groundBeef[2] + "home"[1] + groundBeef[3-1]; lastLetter = groundBeef[groundBeef.length-1];

10 The following is a formula to retrieve a substring: strExpr.substring( index1, index2 ) where strExpr is any valid string expression and index1 ≤ index2 are integer expressions with values in the range from 0 through strExpr.length. [index1,index2) groundBeef = "hamburger"; hamburger 012345678 kwikTripWord = groundBeef.substring(4,8); growl = groundBeef.subtring(6,groundBeef.length); porker= groundBeef.substring(0,groundBeef.length-6);

11 hmm = "If the facts don't fit the theory, change the facts. "; blank = hmm[2]; lastSymbol = hmm[ hmm.length-1 ]; diem = "Carpe per diem – seize the check. "; keyword = diem.substring(6,9); expiration= diem.substring(10,13); longWord= " Supercalifragilisticexpialidocious "; word1= longWord.substring(1,5); word2= longWord.substring(9,15); phrase = longWord[16] + word1 + " " + word2 + ". ";


Download ppt "Anyone recognize this string? GACGGGCTCTGACCCCCTT CGCG List other places where you use strings regularly."

Similar presentations


Ads by Google