173k views
3 votes
Assuming that the message variable contains the string "Happy holidays", the statement message.find("days"); returns a. -1b. 10c. 11d. day

User Clark Kent
by
4.8k points

1 Answer

4 votes

Answer:

Answer is b. 10

Step-by-step explanation:

The find() method is used to search the string for a specified value and searches the first occurrence of that value. It returns the position of that specified value. If the value is not found, this method returns -1.

Lets say we have a message variable that contains the string Happy holidays.

message = "Happy holidays"

We use the method find() to find days word from the Happy holidays string in the message variable.

The find() method will find the position of day.

If we look at the string Happy holidays we see that the word day is at the 10th position of the string.

H 1

a 2

p 3

p 4

y 5

h 6

o 7

l 8

i 9

d 10

a 11

y 12

s 13

So it is at 10th position so the statement

message.find("days")

returns 10

User Glenn Utter
by
3.9k points