vb6 - Number of occurences in a string -
I am a total noob, as far as the scene goes original, in class I need to do the following: "A Write a program that requests a sentence from the user and then records the number of times of each letter in the alphabet. "
How do I count the number of happenings in the string?
Sorry for the question and noob question. As Dave said, the easiest solution would be for length 26 (for English), and Loop through each letter in the string, increasing the right array element. You can use the ASCII value of each letter, to identify which sheet is it, then translate the ASCII number of the letter into this index number:
Dimensions array dimension letter (up to 25-25) for 26 dimensions Long long time as "temporary index number dim tmpIdx 'temporary character dim tmpChar string checkstr to check in as head Chekstrakt string as string =" How many of my other letters? " Make changes in all letters of each letter (since the upper case of each letter is' ASCII value different than its lower case ') Checksat = lcci (check)' through each character, lane for N = 1 (checksat) 'Turn on character tmpChar = mid (checksr, n, 1)' Is the character a letter? If ASC (TMPAR) & gt; = ASC (A 'A')) and (ASC (TMPHR) and LT; = ASC ("Z"), the letter of the calculolet index number ASCII number TMPIDX = ASC (TMPCR) - AC ("A") Increase count LetterCount (tmpIdx) = LetterCount (tmpIdx) + 1 End if Next n 'Now print result n = 0 to 25 chr for print (asc ("a") + n) & amp; "-" & amp; CSTR (Letter Content (N)) Next N
Comments
Post a Comment