-
Notifications
You must be signed in to change notification settings - Fork 27
Jerry Samuels Jr. #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,20 +5,40 @@ instructor_notes: Feel free to re-organize the headings (or add/remove headings) | |
|
|
||
| # What is a String? | ||
|
|
||
| Replace me with your response... | ||
| A string, simply put, is a collection of special characters, letters, and/or numbers. Strings can be as a simple as a name to something longer like an entire sentence or paragraph. | ||
|
|
||
|
|
||
| # What are some examples of information that would be Strings as opposed to some other data type? | ||
|
|
||
| Replace me with your response... | ||
| Since strings are unique in that they can contain a variety of data types like numbers, spaces, letters, and/or special characters, something like a street address (ex: "1132 E. 22nd St.") would be considered a string since it contains, letters, numbers, and special characters. | ||
|
|
||
|
|
||
| # What is one way, using Ruby, to retrieve the 6th character in a String like `"Ada Lovelace"`? How about the 8th character? What happens if you try to retrieve the value of the _99th_ character (Or any character that doesn't exist)? | ||
|
|
||
| Replace me with your response... | ||
| Steps to retrieve the 6th character in "Ada Lovelace": | ||
| 1) string1 = "Ada Lovelace" | ||
| 2) string1[5..5] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The command
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could jut use the literal itself to grab the 6th character: "Ada Lovelace"[5..5] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! You definitely could. I don't mind your variable use, actually. I'm more concerned about the values within the brackets. With that in mind, how might you simplify
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could just type in the one position I'm looking for to return its value, like so: string1[5] |
||
| 3) Returns "o" | ||
|
|
||
| Code to retrieve the 8th character in "Ada Lovelace": | ||
| 1) string1 = "Ada Lovelace" | ||
| 2) string1[7..7] | ||
| 3) Returns "e" | ||
|
|
||
| Steps to retrieve the 99th character in "Ada Lovelace": | ||
| 1) string1 = "Ada Lovelace" | ||
| 2) string1[99..99] | ||
| 3) Returns nil | ||
|
|
||
|
|
||
|
|
||
| # The previous question asks about finding, for example, the 6th character in a String. Is it possible to find the **-6th** (Notice the negative symbol!) character in a String? What does that even mean? | ||
|
|
||
| Replace me with your response... | ||
| It means when searching for the specified substring, the program will count from the end of the string backwards, with the last position of the string being -1 (since there's no such thing as a -0). | ||
|
|
||
|
|
||
| # What is one way, using Ruby, to replace certain characters in a string with some other set of characters? For example, given `"Sumeet Jain"`, how would you replace all of the `e` characters in my name with exclamation marks? (So it would be `"Sum!!t Jain"`.) | ||
|
|
||
| Replace me with your response... | ||
| Code to replace the "e" in Sumeet's name with an exclamation point ("!"): | ||
| 1) name1 = "Sumeet Jain" | ||
| 2) name1.gsub("e","!") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within Ruby Strings, letters, numbers, and special characters are all technically thought of as "characters".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I keep thinking in terms of datatype, but thanks for clarifying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're welcome!