Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing colon's from a string

Status
Not open for further replies.

smcmanus

Technical User
Aug 1, 2001
25
CA
I have a string "00:E0:E4:F2:98:77" and i want to delete the colons. With the code it replaces the string with "00E0E4F29877" which is the back space. How do i get rid of these squares. These numbers are being sent to a text document. Here's how I want it to look. "00E0E4F29877"

Here is my code....

Function del_colon(string_in As String) As String
Dim i As Integer
Dim string_out As String
string_out = ""

For i = 1 To Len(string_in)
If Mid(string_in, i, 1) = ":" Then
Mid(string_in, i, i) = Chr(8)
string_out = string_in
End If

Next

del_colon = string_out

End Function
 
You might try using the intrinsic Replace Function

YourString = Replace(YourString , ":", vbNullString)

The code that you have will replace the colons with a backspace character, which is not the same as removing the characters. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
If using VB6 or higher:

Dim Test As String
Test = Replace("00:E0:E4:F2:98:77", ":", "")
Debug.Print Test Swi
 
Try the adjustments made below.

Function del_colon(string_in As String) As String
Dim i As Integer
Dim string_out As String
string_out = ""

For i = 1 To Len(string_in)
If Mid(string_in, i, 1) <> &quot;:&quot; Then
string_out = string_out & Mid(string_in, i, 1)
End If
Next

del_colon = string_out

End Function Thanks and Good Luck!

zemp
 
If you do NOT have VB6 or higher:

Dim InString As String
Dim OutString As String
Dim CleanString() As String
Dim i As Integer

InString = &quot;00:E0:E4:F2:98:77&quot;

CleanString() = Split(InString, &quot;:&quot;)

For i = 0 To UBound(CleanString)
OutString = OutString & CleanString(i)
Next

Debug.Print OutString Swi
 
Yes, well that won't work Swi since, like Replace, Split doesn't exist in versions of VB prior to 6...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top