if the last 4 chars in my string(result) are " AND" or the last three chars are " OR" I would like to remove these from the string. So far I have am trying result.trimend and a few other methods but am unsure how to get it working.
Thanks
if the last 4 chars in my string(result) are " AND" or the last three chars are " OR" I would like to remove these from the string. So far I have am trying result.trimend and a few other methods but am unsure how to get it working.
Thanks
Dim yourString as string = "sfsdsfd OR "
yourString = CleanString(yourString)
Function CleanString(byval theString as String) as String
'clean the last spaces
theString = theString.TrimEnd()
If theString .EndsWith("OR")) Then
theString = theString .Substring(0, yourString.Length - 2)
Else if yourString.EndsWith("AND")) Then
theString = theString .Substring(0, yourString.Length - 3)
End If
Return theString
End Function
You could also use regex:
Dim regex As New Regex("\s$|\s?and\s?|\s?or\s?", RegexOptions.IgnoreCase)
Dim mystring As String = "asdfasd AND "
mystring = regex.Replace(mystring, "")