
Help with String manipulations
I also have to manipulate character strings and I have found the following
to be usefull.
'***************************************************************************
***************
'Deletes all occurences of the character you pass in p_DelChar in p_TgtStr
'***************************************************************************
***************
Function DeleteChar(p_TgtStr As String, p_DelChar As String)
Dim Result As String, Pos As Integer
Result = p_TgtStr
Pos = InStr(Result, p_DelChar)
While Pos > 0
Result = Left$(Result, Pos - 1) + Right$(Result, Len(Result) - Pos)
Pos = InStr(Result, p_DelChar)
Wend
DeleteChar = Result
End Function
'***************************************************************************
*
'Deletes all characters not between 0 and 9
'***************************************************************************
*
Function DIGITSONLY(p_TgtStr As Variant) As String
Dim p_Result As String, p_TgtLen As Integer, i As Integer, p_ChrVal As
Integer, p_ChrStr As String
If IsNull(p_TgtStr) Then
p_Result = ""
Else
p_TgtLen = Len(p_TgtStr)
For i = 1 To p_TgtLen
p_ChrStr = Mid$(p_TgtStr, i, 1)
p_ChrVal = Asc(p_ChrStr)
If ((p_ChrVal > 47) And (p_ChrVal < 58)) Then
p_Result = p_Result + p_ChrStr
End If
Next i
End If
DIGITSONLY = p_Result
End Function
Public Sub ERROR_HIT()
g_ErrorHit = True
BDErrLog g_ErrorJob, g_ErrorDesc
g_ErrorMsg = "Error during " & g_Option & " Build. " & g_ErrorDesc
MsgBox g_ErrorMsg, gc_MB_ICONSTOP, ""
Exit Sub
End Sub
Example of calls:
strip_string = DeleteChar(mid$(input, 1, 15), "-")
strip_string = DIGITSONLY(mid$(input, 1, 15))
Quote:
>How do i retrieve just characters out of a string variable on at a time?