作用
针对字符串,前后位置判断增加或者减少制定的字符串,作用类似于字符串的直接组合。但是程序中增加了一段判断,用于判断前后位置是否已经增减了需要添加的字符串,以防治重复累加(如果需要这样判断的话,对于需要累加的功能,请直接使用字符串的组合)
程序如下
Function specialchar(source As String, symbol As String, action As String, position As String) As String
'============================================================================
' This program is use to convert some special character
' Programmer: Jacky Shu
' action: add / remove
' position: left / right
' symbol: the character you want to handle
' Date: 2008-05-09
' How to use it - example
' specialchar("ABCDEFG","ABC","remove","left") = "DEFG"
' specialchar("ABCD","EFG","add","right") = "ABCDEFG"
'============================================================================
Dim x As Integer
Dim y As Integer
specialchar = source
If action = "add" Then
If position = "left" Then
x = Len(symbol)
If Left(source,x) <> symbol Then
specialchar = symbol & source
End If
Elseif position = "right" Then
x = Len(symbol)
y = Len(source)
If Right(source,x)<>symbol Then
specialchar = source & symbol
End If
End If
End If
If action = "remove" Then
If position = "left" Then
x= Len(symbol)
y = Len(source)
If Left(source,x) = symbol Then
specialchar = Right(source,(y-x))
End If
Elseif position = "right" Then
x = Len(symbol)
y = Len(source)
If Right(source,x) = symbol Then
specialchar = Left(source,(y-x))
End If
End If
End If
End Function
针对字符串,前后位置判断增加或者减少制定的字符串,作用类似于字符串的直接组合。但是程序中增加了一段判断,用于判断前后位置是否已经增减了需要添加的字符串,以防治重复累加(如果需要这样判断的话,对于需要累加的功能,请直接使用字符串的组合)
程序如下
Function specialchar(source As String, symbol As String, action As String, position As String) As String
'============================================================================
' This program is use to convert some special character
' Programmer: Jacky Shu
' action: add / remove
' position: left / right
' symbol: the character you want to handle
' Date: 2008-05-09
' How to use it - example
' specialchar("ABCDEFG","ABC","remove","left") = "DEFG"
' specialchar("ABCD","EFG","add","right") = "ABCDEFG"
'============================================================================
Dim x As Integer
Dim y As Integer
specialchar = source
If action = "add" Then
If position = "left" Then
x = Len(symbol)
If Left(source,x) <> symbol Then
specialchar = symbol & source
End If
Elseif position = "right" Then
x = Len(symbol)
y = Len(source)
If Right(source,x)<>symbol Then
specialchar = source & symbol
End If
End If
End If
If action = "remove" Then
If position = "left" Then
x= Len(symbol)
y = Len(source)
If Left(source,x) = symbol Then
specialchar = Right(source,(y-x))
End If
Elseif position = "right" Then
x = Len(symbol)
y = Len(source)
If Right(source,x) = symbol Then
specialchar = Left(source,(y-x))
End If
End If
End If
End Function