473,654 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to extract part of a string?

87 New Member
Is there a function, or a combination of functions, in MS Access 2007 that will allow me to extract part of a string?

I have a database text field "Email" that contains a person's name and email address enclosed in brackets. Not all field values have a name, but each has an email address contained by brackets. Here are 3 example field values:

John Smith <johnsmith@emai l.com>
<marysmith@emai l.com>
Willard Smith <willardjsmith@ email.com>

What I want is to extract is the email address from between the brackets. The email address is always in the brackets as shown above.

Any advice or suggestions you can offer would be greatly appreciated.
Apr 2 '10 #1
2 7434
yarbrough40
320 Contributor
Are you looking for a solution using SQL or VB?

if VB then, not sure if there is an easier way to do this but you could use a combination of the InStr() function and the Substring() function...
something like this:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim s As String 
  3. s = Text1.Value        'THIS IS THE WHOLE STRING
  4.  
  5. Dim i1 As Integer = InStr(s, "<") 
  6. Dim i2 As Integer = InStr(s, ">")
  7. Dim MyEmail As String = s.Substring(i1, i2 - (i1 + 1))
  8. MsgBox(MyEmail)
Apr 2 '10 #2
ADezii
8,834 Recognized Expert Expert
  1. Function Definition:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fExtractEMailAddr(strString As String) As Variant
    2.   If InStr(strString, "<") > 0 And InStr(strString, ">") > 0 Then
    3.     fExtractEMailAddr = Mid$(strString, InStr(strString, "<") + 1, _
    4.                         (InStr(strString, ">") - InStr(strString, "<")) - 1)
    5.   Else
    6.     fExtractEMailAddr = Null
    7.   End If
    8. End Function
  2. Sample Function Calls and Results:
    Expand|Select|Wrap|Line Numbers
    1. Debug.print fExtractEMailAddr("Willard Smith <willardjsmith@email.com>")
    2. 'will yield
    3. willardjsmith@email.com
    Expand|Select|Wrap|Line Numbers
    1. Debug.print fExtractEMailAddr("Willard Smith <willardjsmith@email.com")
    2. 'will yield (missing '>')
    3. Null
Apr 2 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
9523
by: Lauren Quantrell | last post by:
Is there anyway to extract part of a string in a stored procedure using a parameter as the starting point? For example, my string might read: x234y01zx567y07zx541y04z My Parameter is an nvarchar and the value is: "x567y" What I want to extract is the two charachters after the parameter, in this case "07". Can anyone shed some light on this problem? Thanks, lq
4
30197
by: rdraider | last post by:
Is there a function that will extract part of a string when the data you want does not occur in a specific position? Field "REF" is varchar(80) and contains an email subject line and the email recipients contact name Example data: Rec_ID REF 1 Here is the information you requested (oc:Johm Smith) 2 Thanks for attending our seminar (oc:Peggy Sue Johnson)
3
5995
by: Joe | last post by:
I'm trying to extract part of html code from a tag to a tag code begins with <span class="boldyellow"><B><U> and ends with TD><TD> <img src="http://whatever/some.gif"> </TD></TR></TABLE> I was thinking of using a regular expression however I having hard time getting the desired string. I use htmlSource = urllib.urlopen("http://address/") s = htmlSource.read() htmlSource.close()
1
2087
by: Patrick Sullivan | last post by:
I am trying to extract two parts of a number from an array element. Numbers are in the format of 1.10, 2.50, 11.10, etc. Floor and ceiling won't work right because close to 1.00, I get a zero, and I need the actual integer part and the fraction part as an int, too.. TIA here is the data fields(0) = "Alena Sobran" fields(1) = "4/4/1977"
7
2877
by: teo | last post by:
hallo, I need to extract a word and few text that precedes and follows it (about 30 + 30 chars) from a long textual document. Like the description that Google returns when it has found a given word. In example from:
9
9303
by: flit | last post by:
Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? like remove the fields below: " Return-Path: X-Original-To: Received: from
7
7610
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and can't seem to figure it out. Here is what I have so far. p = POP3("mail.server.com")
1
4783
by: Alberto Sartori | last post by:
Hello, I have a html text with custom tags which looks like html comment, such: "text text text <p>text</ptext test test text text text <p>text</ptext test test <!-- @MyTag@ -->extract this<!-- /@MyTag@ --> text text text <p>text</ptext test test <!-- @MyTag@ -->and this<!-- /@MyTag@ --> text text text <p>text</ptext test test"
1
2716
by: Edwin.Madari | last post by:
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs......as show below... import urllib line = "GET...
2
4673
by: MaryJolly | last post by:
I want to extract number part from a string. I am doing project in VB6 and my MSFlexGrid control contains certain codes in the first column.eg. EC101,CS104,etc. I want to extract the number part from the text.
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8706
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.