Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Removing Characters and Strings from a String

 
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access
View previous topic :: View next topic  
Author Message
neonasafluni
New Member


Joined: 03 Feb 2007
Posts: 5
Location: West Bend, WI

PostPosted: Wed Jun 02, 2010 9:40 am    Post subject: Removing Characters and Strings from a String Reply with quote

I am often faced with a problem of a string that needs to have certain characters removed from it. With the advent of the Replace() function, the problem becomes more manageable.

For instance, if you wanted to remove all of a's from a particular string, you could do the following:

Code:
Debug.print Replace("abababa", "a", "")


This is nice when you only have a single character that you want removed, but if you have a long list of suspects, you will have to do some serious copy and paste. You can avoid that by using the following function:

Code:
public Function StripOut(From as string, What as string) as string

    Dim i as Integer

    StripOut = From
    for i = 1 to len(What)
        StripOut = Replace(StripOut, mid$(What, i, 1), "")
    next i

End Function


Just place it somewhere in your code (preferably in a module), and call it like this:

Code:
Debug.print StripOut("abcdefg", "bdf")


This will return a string that had all of its 'b', 'd', and 'f' characters removed.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group