1 / 11

Strings

Strings. String. Anyone recognize this string?. GACGGGCTCTGACCCCCTTCGCG. List other places where you use strings regularly. String. A string (text) is made up of keyboard (and other) possible symbols. Strings in Programming. Most programming languages support String data.

ted
Download Presentation

Strings

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Strings

  2. String Anyone recognize this string? GACGGGCTCTGACCCCCTTCGCG List other places where you use strings regularly.

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

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

  6. Strings Concatenation 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. String Length Every string has a length – the count of its characters. bestActor = "Jack Nicholson"; bestActor.length is 14 lyric1 = "We are in the crowd, we’re c-comin’ out"; lyric1.length is 39 gettysburg = "Four score and seven years ago ... "; gettysburg.length is 35

  8. Character Positions 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"; 0 1 2 3 4 5 6 7 8

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

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

  11. More Strings Manipulation 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 + ". ";

More Related