Remove Word In TextBox

摘要:Remove Word In TextBox

psSeperator = ,
Example 1

input :

1)Aaa, psRemoveWord (bbb) , cccc

2)Aaa, psRemoveWord , cccc

Output :

aaa, ccc

 

Example 2

input

psRemoveWord, cccc

Output

ccc

 

Example 3
input
cccc,psRemoveWord
Output
ccc 

 

 

    Private Sub RemoveWordInTextBox(ByVal psRemoveWord As String, ByRef ptxtBox As TextBox, ByVal psSeperator As String)
        Try

            Dim lsTempString As String
            Dim lsReplaceWord As String
            Dim liIndexOfReplaceWord As Integer
            Dim liStartIndex As Integer
            Dim liEndIndex As Integer

            liIndexOfReplaceWord = ptxtBox.Text.IndexOf(psRemoveWord)
            If liIndexOfReplaceWord > -1 Then
                lsTempString = ptxtBox.Text.Substring(0, liIndexOfReplaceWord)
                If lsTempString.LastIndexOf(psSeperator) > -1 Then
                    liStartIndex = lsTempString.LastIndexOf(psSeperator)
                    ' Set the start index after the comma in front of the word e.g ,(startIndex)word
                    liStartIndex += 1
                Else
                    liStartIndex = 0
                End If
                liEndIndex = ptxtBox.Text.IndexOf(psSeperator, liIndexOfReplaceWord)
                If liStartIndex > liEndIndex Then
                    liEndIndex = ptxtBox.Text.Length
                    ' To remove the comma in front of the word
                    If liStartIndex > 0 Then
                        liStartIndex = liStartIndex - 1
                    End If
                Else
                    liEndIndex = ptxtBox.Text.IndexOf(psSeperator, liIndexOfReplaceWord)
                    ' Add to remove the comma behind the word
                    liEndIndex += 1
                End If

                lsReplaceWord = ptxtBox.Text.Substring(liStartIndex, liEndIndex - liStartIndex)
                ptxtBox.Text = vntFixNull(ptxtBox.Text.Replace(lsReplaceWord, BLANK))
            End If

        Catch Err As Exception
            Call ErrHandler(Err.Message, APP_NAME)
        End Try
    End Sub

 

 

 

 

------------------

熱愛生命 喜愛新奇 有趣的事物

 

過去 是無法改變
將來 卻能夠創造

 

希望使大家生活更便利
世界更美好

 

a guy who loves IT and life