开发者

Lose the last 3 chars from string variable

开发者_开发百科

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


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, "")


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜