By Zara Nip
Bentley the Dog had a hard time understanding humans, and his employer at the restaurant was close to firing him. His job was to sort foods into different categories, but he couldn’t read and had too short of a memory to remember the appearances of the items. To make it easier for him, Lucky the Cat wrote abbreviations of names of the food items on bags. Stumped by the strange letters, he kept mixing up dog chow, kitty nip, burgers, and grass. Needless to say, the restaurant customers started giving the restaurant bad reviews about mixed up orders. One cow wrote an extremely distressed post about this upon finding that her vegan grass dinner was actually something quite different – a type of meat (the restaurant only served beef so it was no surprise that she had eaten one of her cousins). She had a cow and happily told the waiter that she would stop at no length to post bad reviews of the restaurant on the dark SpiderWeb if no action was taken.
Bentley didn’t understand the problem, and his employer was growing weary. As a last resort, he tasked Lucky with helping Bentley. Luckily for Lucky, he was an excellent learner. She taught him about something called strings and even made a handy (or rather “pawy” because Bentley didn’t have hands) pamphlet complete with pictures, which she proceeded to explain.
The pamphlet stated the following:
Letters had different numbers assigned to them.
T(0) R(1) E(2) A(3) T(4) S(5)
For example, dog chow was str.substring(0,7) because there were 8 characters – including the space, burgers was str.substring(0,6), etc... Strings can be named differently, and this string is called str.
(Bentley had a brief itching need to know why the sequence started at 0, but it was overshadowed by the mention of a trea – wait SQUIRREL! SQUIRREL!)
The way to write a certain number of letters in a string is by using str.substring.
Using TREATS,
str.substring(0,5) = TREATS
str.substring(1,2) = R
The first number in parenthesis () is where the string starts and it goes up to the last number (not included), so (1,2) starts at the second character (R) but doesn’t include the third letter (E).
str.length() is another way to define the number of characters in a string. It can be used inside str.substring.
For an example,
str.substring(0,str.length()) is the string, whatever that may be.
(It was boring, but understandable to Bentley. Barking at animals was much easier.)
Lucky said her abbreviations were str.substring (1,str.length()-3). After explaining everything, she asked Bentley if he understood, and he barked at a tree to show his newfound knowledge. She saw it as an absolute win and told Bentley to go back to work. When he got back, he sorted mostly everything correctly (birds were flying right outside the window – it was Bentley’s other, lesser known job to chase them away. Just another occupational hazard.). Thanks to Lucky, their business improved and customer satisfaction increased.
That is, until the owner of the store added hay to the menu.
Comentarios