Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Extracting string parts
Mark Somerville 
    
3 years ago
I am trying to extract all parts of a string that match certain criteria, and then put that in a new record for each instance. The string looks like "1 (1) 2 (2) 3 (3) 4 (4)" and so on, and I would like to extract all the numbers not in brackets to one field with a new record for each number, and the same for all the numbers between brackets to another field.
Richard Rost  @Reply  
           
3 years ago
Looks like a job for String Functions
Alex Hedley  @Reply  
           
3 years ago
Why not have some fun with some RegEx?
Kevin Yip  @Reply  
     
3 years ago
HI Mark, you need to watch the video Richard just mentioned, because you need some of those string functions, and some creativity as well.

First is the creative part: you need to replace all occurrences of "(" with "|(", and all occurrences of ")" with ")|".  Your string will become this, with each number delimited by a "|":

     1 |(1)| 2 |(2)| 3 |(3)| 4 |(4)|

Second, use the Split() function to put all the numbers in an array, using "|" as the delimiter.  Your array will have 9 elements, the first being "1 ", second "(1)", third " 2 ", fourth "(2)", and so on.  There are leading and trailing spaces in some elements, as shown.

Then you use a For Next loop to go through each element in the array.  Use the Trim() function to remove the leading and trailing spaces in each of them.  Then check the presence of "(" in each element.  If an element begins with "(", put the number in one field.  If it doesn't, the other field.

Regarding the numbers with the parentheses, you didn't say whether you want to store the parentheses with the numbers into the field or not.  If not, you need to remove the parentheses in those numbers with the Replace() function as well.

Gary James  @Reply  
      
3 years ago
Alex, I believe this is what he needs:

^((\s*[\d]+\s*)(\(\s*\d+\s*\)))+
Richard Rost  @Reply  
           
3 years ago
Good idea with the |
Kevin Yip  @Reply  
     
3 years ago
But it will cause problems if "|" is contained inside the strings.  In my old job, I used really obscure characters as delimiters, which was still not 100% perfect.  The best way is to avoid using delimiters.  So I actually second the use of regular expressions as others have suggested.  Richard, you may want to add a course on that.  It's not exactly a database topic, so it's widely used in any coding languages, and it's supported in VBA (see picture below).
Kevin Yip  @Reply  
     
3 years ago

Gregory Clancey  @Reply  
    
3 years ago
Yes. Alt-code character charts can be found all over the INTERNET. I often use "https://www.alt-codes.net/" and things like "►", chr(16) or "'", chr(187) as well as many others can be useful.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 2:25:53 AM. PLT: 1s