delete certain variables from string

DrJ

New member
Local time
Yesterday, 21:29
Joined
Jul 30, 2004
Messages
5
Has anyone an idea how to delete certain numbers/letters from a string?

So lets say I have a string "05605080"

And I want all the "0" out of it in a way that this string is left: "5658"

All help is appriciated.

Rob
 
You just need a parsing function you can use in code or a query. A basic example is:
Code:
Function RemoveStuff(sIn as string, sRmv as string) as string
 if len(sRmv) <> 1 then
  msgbox "This is limited to single character removal",,"Sorry Charlie"
  exit function
 end if
 dim LP as integer, sHold as string
 for LP = 1 to len(sIn)
  if mid(sIn,LP,1) = sRmv then
   ' by pass this character
  else
   ' save this character
   sHold = sHold & mid(sIn,LP,1)
  end if
 next LP
 RemoveStuff = sHold
exit function

To Use:
MyString = RemoveStuff(BadString,CharToRemove)

You can search the forms or check the sample DB's also
 
If you're using Access 2000 or higher, you can use the Replace function like this:
Replace("05605080","0","")

If you're using Access 97 (or earlier), you'll need to use code like Fofa's. If speed is not an issue, and you're lazy :), and you have Excel also installed on the same computer, you can make an automation call to use the Excel SUBSTITUTE function.
 

Users who are viewing this thread

Back
Top Bottom