removing special character from string

  • Thread starter Thread starter Guest
  • Start date Start date
Paste the function below into a standard module, and save it.

You can then call the function to strip whichever characters you wish from a
string, e.g.:
=Strip([MyField], "&., ()")


Function Strip(vPhrase, sBadChars As String)
' Purpose: remove any of the characters in sBadChars from vPhrase
Dim sPhrase As String
Dim i As Integer

If IsNull(vPhrase) Or IsEmpty(vPhrase) Or Len(sBadChars) = 0 Then
Strip = vPhrase
Else
sPhrase = vPhrase
i = 1
Do Until i > Len(sPhrase)
Do Until InStr(sBadChars, Mid$(sPhrase, i, 1)) = 0 Or i >
Len(sPhrase)
sPhrase = Left$(sPhrase, i - 1) & Mid$(sPhrase, i + 1)
Loop
i = i + 1
Loop
Strip = sPhrase
End If
End Function
 
thanks Allen Browne its working now.now can u give me code for how to add
controls into report programmatically using a template

Allen Browne said:
Paste the function below into a standard module, and save it.

You can then call the function to strip whichever characters you wish from a
string, e.g.:
=Strip([MyField], "&., ()")


Function Strip(vPhrase, sBadChars As String)
' Purpose: remove any of the characters in sBadChars from vPhrase
Dim sPhrase As String
Dim i As Integer

If IsNull(vPhrase) Or IsEmpty(vPhrase) Or Len(sBadChars) = 0 Then
Strip = vPhrase
Else
sPhrase = vPhrase
i = 1
Do Until i > Len(sPhrase)
Do Until InStr(sBadChars, Mid$(sPhrase, i, 1)) = 0 Or i >
Len(sPhrase)
sPhrase = Left$(sPhrase, i - 1) & Mid$(sPhrase, i + 1)
Loop
i = i + 1
Loop
Strip = sPhrase
End If
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

prad said:
i want to remove special character like &,.,( ),space,from a string
 
prad said:
thanks Allen Browne its working now.now can u give me code for how to
add controls into report programmatically using a template

Allen Browne said:
Paste the function below into a standard module, and save it.

You can then call the function to strip whichever characters you
wish from a string, e.g.:
=Strip([MyField], "&., ()")


Function Strip(vPhrase, sBadChars As String)
' Purpose: remove any of the characters in sBadChars from vPhrase
Dim sPhrase As String
Dim i As Integer

If IsNull(vPhrase) Or IsEmpty(vPhrase) Or Len(sBadChars) = 0 Then
Strip = vPhrase
Else
sPhrase = vPhrase
i = 1
Do Until i > Len(sPhrase)
Do Until InStr(sBadChars, Mid$(sPhrase, i, 1)) = 0 Or i >
Len(sPhrase)
sPhrase = Left$(sPhrase, i - 1) & Mid$(sPhrase, i +
1) Loop
i = i + 1
Loop
Strip = sPhrase
End If
End Function

Here's another version that both exchanges characters and removes anything
that does not have a match in the charsOld string.
?exchange("This is a test", "tsi", "XZ")
XhZ Z a XeZX.
This is essentially the same as the Pick Convert function.

Function Exchange(vPhrase, sCharsOld As String, sCharsNew As String)

Dim sPhrase As String, charold As String, charnew As String
Dim i As Integer
If IsNull(vPhrase) Or IsEmpty(vPhrase) Or Len(sCharsOld) = 0 Then
Strip = vPhrase
Else
sPhrase = vPhrase

For i = 1 To Len(sCharsOld)

charold = Mid$(sCharsOld, i, 1)
charnew = Mid$(sCharsNew, i, 1)
sPhrase = Replace(sPhrase, charold, charnew)

Next i
Exchange = sPhrase
End If
End Function
 
Look in help under CreateControl

However, this is something I amost never do. I always give the end user an
MDE (so it cannot decompile and the user cannot mess it up), and you cannot
open a report in design view in an MDE.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

prad said:
thanks Allen Browne its working now.now can u give me code for how to add
controls into report programmatically using a template

Allen Browne said:
Paste the function below into a standard module, and save it.

You can then call the function to strip whichever characters you wish
from a
string, e.g.:
=Strip([MyField], "&., ()")


Function Strip(vPhrase, sBadChars As String)
' Purpose: remove any of the characters in sBadChars from vPhrase
Dim sPhrase As String
Dim i As Integer

If IsNull(vPhrase) Or IsEmpty(vPhrase) Or Len(sBadChars) = 0 Then
Strip = vPhrase
Else
sPhrase = vPhrase
i = 1
Do Until i > Len(sPhrase)
Do Until InStr(sBadChars, Mid$(sPhrase, i, 1)) = 0 Or i >
Len(sPhrase)
sPhrase = Left$(sPhrase, i - 1) & Mid$(sPhrase, i + 1)
Loop
i = i + 1
Loop
Strip = sPhrase
End If
End Function


prad said:
i want to remove special character like &,.,( ),space,from a string
 
Back
Top