1 / 25

Strings : Getting Stuff Done

Strings : Getting Stuff Done. Basic Recipes. Does this look like an email address?. Basic Recipes. Does this look like an email address? Is there an @. What is that Warning???. Ugly digression…. Basic Recipes. Does this string have a @ in it? Happier compiler version.

Download Presentation

Strings : Getting Stuff Done

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 : Getting Stuff Done

  2. Basic Recipes • Does this look like an email address?

  3. Basic Recipes • Does this look like an email address? • Is there an @

  4. What is that Warning??? • Ugly digression…

  5. Basic Recipes • Does this string have a @ in it? • Happier compiler version

  6. Char vs 1 char string • 'a' is not the same kind of thing as "a" Object Number

  7. Char vs 1 char string • string.at(index) and string[index] give a char • No • Yes

  8. Char vs 1 char string • All other string functions give string • Yes • No

  9. Basic Recipes • Want to separate username and domain:

  10. Basic Recipes • Method 2:

  11. Basic Recipes • I want to replace a @ with #:

  12. Basic Recipes • I want to replace a @ with #: • Shorter version Set one char in stringto new value… must be a char

  13. Basic Recipes • I want to replace a @ with #: • Long version

  14. Chopping • Generally easier to chop as you go:

  15. Chopping • Finding both '-' and then chopping:

  16. Looping • Finding all groups in string like:123-4324-23-34-…-234 • While there is another dash, find dash, print everything up to dash

  17. Looping • By chopping parts off:

  18. Looping • By moving start/end indexes:

  19. Looping Characters • Process each character : • Loop from 0 to length - 1 Current position Current letter

  20. Looping Characters • Backwards

  21. Modifying as we go • Shift all chars by one: • Get current letter • Modify • Replace current letter with changed

  22. Case Study Hex Conversion • Convert hex numbers to decimal: • Possible digits:0-9, A (10), B (11), C (12), D (13), E (14), F (15) • Place values powers of 16: 1 x 4096 + 2 x 256 + 14 x 16 + 9 x 1 = 4841 12E916 = 484110

  23. Case Study Hex Conversion • Need to access each digit • Need to figure out its value • Need to keep track of what place we are in • Need to build up a total

  24. Case Study Hex Conversion • Need to access each digit • Need to figure out its value • char '4' != 4 • But '4' – '0' = 4

  25. Case Study Hex Conversion • Need to access each digit • Need to figure out its value • Need to keep track of what place we are in • Each column is 16 x bigger than one to right • Need to build up a total

More Related