Download presentation
Presentation is loading. Please wait.
Published byCharity Cole Modified over 8 years ago
1
1 Comparing Strings zLcase(string) --- converts a string to lower case Mystring = lcase(yourstring) zUcase(string) --- converts a string to upper case Mystring = ucase(yourstring)
2
2 Comparing Strings zStrconv(string, conversion) --- converts a string based on the value of “conversion” VbUpperCase VbLowerCase VbProperCase (1 st letter in each word to uppercase)
3
3 Comparing Strings zReturns the string modified based on the conversion selected Dim mystr as string Mystr = “summer fun” l1.text = strconv(mystr, vbpropercase) // Summer Fun
4
4 Comparing Strings zPRACTICE: (Thompson p.6-27 Exercise 4) Initials and Uppercase names. Do not need to determine the Initials and display on a label.
5
5 String manipulation zMicrosoft.VisualBasic.Left(string, length) --- returns the number of letters from the start of the string Mystr = “Summer" Left(mystr, 3) // Sum
6
6 String manipulation zMicrosoft.VisualBasic.Right(string, length) --- returns the number of letters from the end of the string Mystr = “Summer” Right(mystr, 3) // mer
7
7 String manipulation zMid(string, start,length) --- takes a string and returns the number of characters starting with START and for the LENGTH mystr = “Summer” l1.caption = mid(mystr, 2, 4) // umme
8
8 String manipulation zLen(string) --- returns the number of characters in a string Mystr = “Summer” Myint = Len(mystr) // 6
9
9 String manipulation zPRACTICE: (Thompson p.6-11 Review 6) display the first letter and last letter entered in a textbox.
10
10 String manipulation zInStr(start, string1, string2) – returns the starting position of a substring. z0 is returned if the substring is not found. zStart is the position in string1 to search for zString1 is the string to be searched zString2 is the string to be searched for Mystr = “Sumer” My2 = “um Intofpos = Istr(1, mystr, my2) // 2
11
11 String manipulation zPRACTICE: (Thompson p.6-12 Review 7) allow for entry of 2 strings in 2 textboxes, display the position of the 1 st word in which the 2 nd word (substring) is found zPRACTICE: (Thompson p.6-12 Review 8) enter a word and then a letter to search for, then display the number of times that letter appears in the word. zPRACTICE: (Thompson p.6-28 Exercise 9) Reverse an entered word.
12
12 String manipulation zStrcomp(string1, string2, vbTextCompare) does not care about case Example: Dim a, b as string A = “apples” B = “oranges” If strcomp(a, b, vbTextCompare) = 0 Then Words are the same Else Words are different End if
13
13 String manipulation zLike --- used to perform textual comparison on strings. zResult = string like pattern zResult is a bolean or integer: zTrue if string matches pattern zFalse if it does not match the pattern
14
14 String manipulation zExample: Pattern forms: ? single character * in place of many characters # single number [] list of characters - a range of characters in a character list, separate characters in a character list
15
15 String manipulation Mystr = “Run” Str = “ ?un” L1.caption = mystr Like str // caption = TRUE
16
16 String manipulation Mystr = “Run” Str = “ ?um” L1.caption = mystr Like str // caption = FALSE
17
17 String manipulation Mystr = “Letter to the Editor” Str = “ Letter to *” L1.caption = mystr Like str // caption = TRUE
18
18 String manipulation Mystr = “Case 977145” Str = “Case 977#” L1.caption = mystr Like str // caption = TRUE
19
19 String manipulation Mystr = “Case 977145” Str = “Case 9#6#” L1.caption = mystr Like str // caption = FALSE
20
20 String manipulation Mystr = “C” Str = “[A,B,C,D]” L1.caption = mystr Like str // caption = TRUE zMystr = “B” Str = “[A-D]” L1.caption = mystr Like str // caption = TRUE
21
21 String manipulation zPRACTICE: (Thompson p.6-29 Exercise 10) Create a program that counts and displays the number of the vowels in a word entered in a textbox.
22
22 String manipulation zPRACTICE:(thompson p.6-20 Case Study ) Create a “Hangman” program that allows a user to enter characters and guess a secret word. The application should then display a message if the user guessed the secret word correctly and how many tries it took...
23
23 String manipulation z...Create a caption that displays a dash for each letter in the word (use large font) zUse a random number to select from several words zStore the secret word in a string and the length of the word as an integer zStore the number of guesses in an integer...
24
24 String manipulation z...Within a loop, display an input box to guess a letter of the word and then search the secret word for any matching letters. If a letter matches, replace the dashes with the correct letters and ask for another letter.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.