U unba1300 Guest Apr 1, 2012 #1 Sorry, this will be an easy answer for some, but I'm still learning. I need to check if a string variable ends with "s", and if it does, remove the "s". I have the check working with EndsWith, but not the replacement. Tried this: Code: Copy varFood(0) = varFoods(0).Replace(LastIndexOf("s"),"") 'and varFood(0) = varFoods(0).SubString2(0, LastIndexOf("s")) Thanks.
Sorry, this will be an easy answer for some, but I'm still learning. I need to check if a string variable ends with "s", and if it does, remove the "s". I have the check working with EndsWith, but not the replacement. Tried this: Code: Copy varFood(0) = varFoods(0).Replace(LastIndexOf("s"),"") 'and varFood(0) = varFoods(0).SubString2(0, LastIndexOf("s")) Thanks.
NJDude Expert Licensed User Longtime User Apr 1, 2012 #2 You have to use EndsWith Code: Copy If varFoods(0).EndsWith("s") Then ... Upvote 0
NJDude Expert Licensed User Longtime User Apr 1, 2012 #4 Ok, like this then: Code: Copy Dim MyString As String MyString = "Apples" If MyString.EndsWith("s") Then MyString = MyString.SubString2(0, MyString.Length -1) End If Msgbox(MyString, "") Upvote 0
Ok, like this then: Code: Copy Dim MyString As String MyString = "Apples" If MyString.EndsWith("s") Then MyString = MyString.SubString2(0, MyString.Length -1) End If Msgbox(MyString, "")