The PERSONSWAP() function, replaces words like "me" with "you" and "you" with "me"

------------------------------------------------------------------------------------
Public Function PersonSwap_A(Caller As String, StringOfWords As String) As String
Dim MethName As String = "PersonSwap_A"
Dim Result As String = ""
If StringOfWords.IsValid Then
Result = StringOfWords.Trim
' ****************************
' Always swap the multi-words before the single words
' ****************************
'* First person - multi words
Result = WordReplace2(Result, "I am", "|you are|")
Result = WordReplace2(Result, "am I", "|are you|")
Result = WordReplace2(Result, "Was I", "|were you|")
' ======================================================================
'---------- SPECIAL CONVERSIONS FOR QUESTIONS ---------------
' Normally 'Are You' would be rplcd with 'Am I' but I want
' The bot's answers to contain the words 'I am' or 'I am not'
' Result = WordReplace1(Result, "are you", "|am I|")
Result = WordReplace1(Result, "are you", "|I am|") ' Replies can have "I am ..." or "I am not..."
Result = WordReplace1(Result, "can you", "|I can|")
Result = WordReplace1(Result, "will you", "|I will|")
Result = WordReplace1(Result, "did you", "|I did|")
Result = WordReplace1(Result, "have you", "|I have|")
Result = WordReplace1(Result, "would you", "|I would|")
Result = WordReplace1(Result, "could you", "|I could|")
Result = WordReplace1(Result, "do you", "|I do|") ' Replies can have "I do ..." or "I do not..."
'
' Result = WordReplace1(Result, "are you", "|I am|")
' Result = WordReplace1(Result, "are you", "|I am|")
'---------- SPECIAL CONVERSIONS FOR QUESTIONS ---------------
' ======================================================================

'* Second Person - multi words
Result = WordReplace1(Result, "you are", "|I am|")
Result = WordReplace2(Result, "were you", "|I was|")


'* First person - single words
Result = WordReplace2(Result, "I`m", "|you`re|")
Result = WordReplace1(Result, "me", "|you|")
Result = WordReplace1(Result, "I", "|you|")
Result = WordReplace2(Result, "I`ll", "|you will|")
Result = WordReplace1(Result, "my", "|your|")
Result = WordReplace2(Result, "myself", "|yourself|")
Result = WordReplace2(Result, "mine", "|yours|")

'* Second Person - single words
Result = WordReplace1(Result, "your", "|my|")
Result = WordReplace2(Result, "yourself", "|myself|")
Result = WordReplace2(Result, "yours", "|mine|")
Result = WordReplace2(Result, "you`re", "|I`m|")


' Special case - "YOU" can map to either "ME" or "I"
Result = WordReplace1(Result, "you", "|me|") '?
' Result = WordReplace1(Result, "you", "|I|") '?
' If "you" comes after the verb, replace it with "me"
' If "you" comes before the verb, replace it with "I"

Result = Replace(Result, "|", "")

Else
' This function was called with an empty string
Result = "Error 42" ' THIS IS JUST A 'MADE UP' ERROR NUMBER
End If
Return Result
End Function
' *** Updated Mar 6 2023 ***

NOTES:
In my code, I replace the apostrophys (') with the character (`) to avoid
problems with in-line SQL.

The functions "WordReplace2()" and "WordReplace1()" are wrappers around
the Visual Basic, "REPLACE()" function, to handle a STRING OF WORDS,
(Complete words, separated by spaces)

The PIPE (|) character is used to prevent the function from replacing
a word and then changing the new word back to the original word.
At the end of the function, the PIPE character is removed.

' Replaces one full word for another, using spaces as word boundries
Public Function WordReplace1(StringOfWords As String, FindString As String, Replacement As String) As String
' Watch out for caseing !
Dim Result As String
StringOfWords = " " & StripDoubledSpaces(StringOfWords) & " " ' trim original & add leading & trailing spaces
FindString = " " & StripDoubledSpaces(FindString) & " "
Replacement = " " & StripDoubledSpaces(Replacement) & " "
Result = Replace(StringOfWords, FindString, Replacement, 1, -1, CompareMethod.Text)
' Watch out for caseing !
Return CapFirstLetter(Result.Trim)
End Function

' These functions rely on spaces as word boundries


' Replaces one full word for another, using spaces as word boundries
Public Function WordReplace2(StringOfWords As String, Find As String, ReplaceWith As String) As String
' Watch out for caseing !
Dim Result As String = ""
StringOfWords = StripDoubledSpaces(StringOfWords)
StringOfWords = Replace(StringOfWords, "'", "`")
Find = StripDoubledSpaces(Find)
ReplaceWith = StripDoubledSpaces(ReplaceWith)

Result = Replace(" " & StringOfWords & " ", " " & Find & " ", " " & ReplaceWith & " ", 1, -1, CompareMethod.Text)
' Watch out for caseing !
Return Result.Trim
End Function

The Visual Basic "Replace()" function is used to replace a string of characters in
another string of characters. If you want to replace a WORD with another WORD,
then use one of the "WordReplace()" functions. Both of the "WordReplace()" functions
work slightly differently. If one does not work for you, try the other one.