Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Function which automatically checks the first letter of what's fed into it. Will see if it's correct to use 'An' or 'A'. Supports capitalisation and proper nouns. If the item, npc etc. has $ as the first character of it's name, it'll be read as a proper noun. Of course, you'll have to remove this when rendering item names and stuff on the map.
Code: Public Function CheckGrammar(ByVal Word As String, Optional ByVal Caps As Byte = NO) As String
Dim FirstLetter As String * 1
FirstLetter = LCase$(Left$(Word, 1))
If FirstLetter = "$" Then
CheckGrammar = (Mid$(Word, 2, Len(Word) - 1))
Exit Function
End If
If Caps Then CheckGrammar = "A " & Word Else CheckGrammar = "a " & Word
If FirstLetter = "a" Or FirstLetter = "e" Or FirstLetter = "i" Or FirstLetter = "o" Or FirstLetter = "u" Then
If Caps Then CheckGrammar = "An " & Word Else CheckGrammar = "an " & Word
End If
End Function
Example:
Code: msg = "You picked up " & CheckGrammar(Trim(Item(GetPlayerInvItemNum(index, n)).Name)) & "."
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
DFA Wrote:its fail
it wont work on words like hour and others
It's for nouns only you fucking retard.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Just for the fun of it, since we're fixing grammar mistakes.
I before E except after C
Code: Dim Loc As Integer
If InStr(1, Word, "ei") 0 Or InStr(1, Word, "ie") 0 Then
For Loc = 2 To Len(Word)
If Mid(Word, Loc, 2) = "ie" And Mid(Word, Loc - 1, 1) = "c" Then
Word = Left(Word, Loc - 1) & "ei" & Right(Word, Len(Word) - Loc - 1)
ElseIf Mid(Word, Loc, 2) = "ei" And Mid(Word, Loc - 1, 1) "c" Then
Word = Left(Word, Loc - 1) & "ie" & Right(Word, Len(Word) - Loc - 1)
End If
Next Loc
End If
(I know there are exceptions, but eh  )
Btw Robin, hourglass is a noun, but it's one of the few exceptions that use an that doesn't start by a vowel.
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
[quote="JokeofWeek"]Btw Robin, hourglass is a noun, but it's one of the few exceptions that use an that doesn't start by a vowel.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
GIAKEN Wrote:Pfft I already did this.
Holy fucking shit you're alive.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
If it sounds like it starts with a vowel, it's possed to use an, not a. I used to know a LOT of those words, but I can't remember them anymore. Lol.
This is something that's been needed in MS for awhile. It seems like it's simple and would have no real change, but it makes a big difference imo.
Robin Wrote:GIAKEN Wrote:Pfft I already did this.
Holy fucking shit you're alive.
I just moved out of my parents house.
Anyways, I did this check grammar thing in Elysium Diamond 3 a long ass time ago. Here's my function:
Code: Public Function CheckGrammar(ByVal Word As String, Optional ByVal Caps As Byte = NO) As String
Dim FirstLetter As String * 1
FirstLetter = LCase$(Left$(Word, 1))
If Caps Then CheckGrammar = "A" Else CheckGrammar = "a"
If FirstLetter = "a" Or FirstLetter = "e" Or FirstLetter = "i" Or FirstLetter = "o" Or FirstLetter = "u" Then
If Caps Then CheckGrammar = "An" Else CheckGrammar = "an"
End If
End Function
Oh haha I see what you did thar Robin. Anybody notice how much alike they are?
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
GIAKEN Wrote:Oh haha I see what you did thar Robin. Anybody notice how much alike they are? 
Probably your code.
I just found it in Essence.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Here's a tiny improvement:
using "ass"
Quote:%Faster 185.7| 71.4| 71.4| 64.3| 71.4| 64.3| 71.4| 64.3| 84.6| 71.4
Test1 40| 24| 24| 23| 24| 23| 24| 23| 24| 24
Test2 14| 14| 14| 14| 14| 14| 14| 14| 13| 14
using "test"
Quote:%Faster 46.7| 46.7| 64.3| 53.3| 53.3| 33.3| 33.3| 33.3| 53.3| 33.3
Test1 22| 22| 23| 23| 23| 20| 20| 20| 23| 20
Test2 15| 15| 14| 15| 15| 15| 15| 15| 15| 15
Test1 was using the original code.
Test2 is:
Code: Private Function CheckGrammar(ByVal Word As String, Optional ByVal Caps As Byte = 0) As String
Dim FirstLetter As String * 1
FirstLetter = LCase$(Left$(Word, 1))
If FirstLetter = "$" Then
CheckGrammar = (Mid$(Word, 2, Len(Word) - 1))
Exit Function
End If
If FirstLetter Like "*[aeiou]*" Then
If Caps Then CheckGrammar = "An " & Word Else CheckGrammar = "an " & Word
Else
If Caps Then CheckGrammar = "A " & Word Else CheckGrammar = "a " & Word
End If
End Function
Something less repetitive. Not sure if it's any faster. Also this function is made to be faster for words that need "An" because statements in an Else are always slower than statements in the actual If. I'm not sure which would come up more often (needing an An or just A), but to change it just add If Not FirstLetter and switched the statements around.
Code: Private Function CheckGrammar(ByVal Word As String, Optional ByVal Caps As Byte = 0) As String
Dim FirstLetter As String * 1
FirstLetter = LCase$(Left$(Word, 1))
If FirstLetter = "$" Then
CheckGrammar = (Mid$(Word, 2, Len(Word) - 1))
Exit Function
End If
If FirstLetter Like "*[aeiou]*" Then
If Caps Then CheckGrammar = "An " Else CheckGrammar = "an "
Else
If Caps Then CheckGrammar = "A " Else CheckGrammar = "a "
End If
CheckGrammar = CheckGrammar & Word
End Function
|