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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a hypen from a value ( 12-13) 1

Status
Not open for further replies.

campbere

Technical User
Oct 10, 2000
146
US
I would like to delete a hyphen from a value. For example I have the value 12-13 and I want 1213. I thought about using the Instr to find the position of the - and then use that possibly to remove the -. But I am not sure what function does this. Does anyone have any ideas or could point me in the right direction? If it matters my field is a varchar(2) and it is in Oracle.

Thanks
 
You could use the Instr() function like this:
Code:
Option Explicit

Sub Test()
    MsgBox RemoveHyphen("12-13")
End Sub

Public Function RemoveHyphen(sVal As String) As String
    Dim iPos As Long
    iPos = InStr(1, sVal, "-")
    If iPos > 0 Then
        RemoveHyphen = Left(sVal, iPos - 1) & Right(sVal, Len(sVal) - iPos)
    Else
        RemoveHyphen = sVal
    End If
End Function
 
if you have vb6 the you could use the replace function

MsgBox Replace("12-13","-","")


David Paulson


 
The Instr function is one way to go. It identifies the position the item being searched for occurs in and if it does not occur it returns a zero.
example:
dim strTest as string
dim strNew as string
dim intMypos as integer
strTest = '12-13'

intMyPos = Instr(1, strTest, "-")

strnew = left$(strtest, intMyPos-1) + mid$(strtest, intmypos+1)

This should do it. Also check MSDN help on the Instr function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top