Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Regular Expression support in visual basic

Posted on 2003-03-28
9
Medium Priority
?
271 Views
Last Modified: 2013-11-25
I am in need of reference material on using regular expressions in visual basic - not vbscript but visual basic. I need to replace the occurences of the following characters inside a string '. : ; / | ? *'. I have tried microsoft but their site has just to many levels...

0
Comment
Question by:roustnissen
9 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8224570
0
 

Author Comment

by:roustnissen
ID: 8224670
... well not quite!
what I need is reference material so that can write my own expressions in visual basic 6.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8224692
You want to parse yourself string finding patterns in it and replacing them?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:roustnissen
ID: 8224717
Yes, I am having a string that might contain one or more of the above and I need to replace that char with a '.'.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8224771
So it doesn't need to be regular expressions:

x = replace(x,".", ".")
x = replace(x,":", ".")
x = replace(x,";", ".")
...
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 8224796
Try this:

Private Sub Command1_Click()
    MsgBox ReplaceChars("this is ; / a tes;t string?*", ".:;/|?*", ".")
End Sub

Private Function ReplaceChars(ByVal pstrX As String, ByVal pstrFind As String, ByVal pstrReplace As String) As String
Dim intI As Integer
    For intI = 1 To Len(pstrFind)
        pstrX = Replace(pstrX, Mid$(pstrFind, intI, 1), pstrReplace)
    Next intI
    ReplaceChars = pstrX
End Function
0
 
LVL 3

Assisted Solution

by:emadat
emadat earned 400 total points
ID: 8225149
Hi..
emoreau's solution is an elegant one.

However; if you still insist on using regular expressions;  you can use a Windows Script object to so that.
Here is an article from Microsoft on how to use it -including an example-:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting051099.asp

Download Windows Script 5.6 for Windows 2000 from: http://www.microsoft.com/downloads/details.aspx?FamilyId=C717D943-7E4B-4622-86EB-95A22B832CAA&displaylang=en

Download Windows Script 5.6 Documentation from: http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en


Also here are some links to tutorials:

http://www.devarticles.com/art/1/302/1
http://www.aivosto.com/vbtips/regex.html
http://nltk.sourceforge.net/tutorial/regexps/nochunks.html
http://www.evolt.org/article/rating/20/22700/
0
 

Expert Comment

by:CleanupPing
ID: 8531413
Hi roustnissen,
This old question (QID 20566347) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440824
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Split between emoreau and emadat

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question