topic: string handling Flashcards

(9 cards)

1
Q

what does string.length show/ mean

A

number of characters , including spaces in the data in the variable has

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does string.substring show/ mean

A

(the starting position, number of characters)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what would the code
someText = “Computer Science”
print(someText.substring(3,3))
print out?

A

put

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is a string

A

an object that represents a sequence of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what would be printing out with : myString.substring(5,10)
if myString = “Samsung exploding galaxies”

A

ng ex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does temp.substring(j,1) mean

A

extracts a single character from the word starting at position j so that each character can be stored individually in the 2D display array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The algorithm will make use of a function, contains, that compares two strings and checks
if the second string contains the first string. For example, calling the function with (“fox”,
“foxhound”) this would return true.
The function needs to:
* Take two strings as parameters, string1 and string2
* return true if string1 is contained within string2, or both strings are identical
* return false if string1 is not contained within string2
Write, using pseudocode, the function contains.

A

function contains(string1, string2)
wordInside = false
for i = 0 to (string2.length – string1.length)
if string2.substring(i, string1.length) ==
string1 then

wordInside=true
endif
next i
return wordInside
endfunction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how to get a string length
using the variable stringname

A

stringname.length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to get a substring using the variable name stringname

A

stringname.subString(startingPosition, numberOfCharacters)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly