473,385 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to extract the last word in a string?

2
I've imported a CSV file into my Access Database and the Address field also contains a City name, ie:
123 SE Main St. #A Seattle
8235 127th St Ct E Tacoma
47 Wilson River Highway Unit H1 Bremerton

I want to parse the City into a new field and then delete the city name from the address field. I can use this expression in a query to parse to the firstspace:

Expr: Left([mailaddr1],InStr([mailaddr1]," "))

but is there a function which will easily allow me to extract the last word in a string?
Mar 11 '11 #1
6 7010
TheSmileyCoder
2,322 Expert Mod 2GB
You can use Right and InStrRev.
TheSmileyCoder
Mar 11 '11 #2
ADezii
8,834 Expert 8TB
Here is a Custom Function that I created for you, which will do what you request. The Function Definition, Sample Calls, as well as Output are listed below:
Expand|Select|Wrap|Line Numbers
  1. Public Function fExtractLastWord(strWord As String) As Variant
  2. Dim varRet As Variant
  3.  
  4. varRet = Split(strWord, " ")
  5.  
  6. fExtractLastWord = varRet(UBound(varRet))
  7. End Function
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fExtractLastWord("8235 127th St Ct E Tacoma")
  2. Tacoma
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fExtractLastWord("47 Wilson River Highway Unit H1 Bremerton")
  2. Bremerton
Expand|Select|Wrap|Line Numbers
  1. Debug.print fExtractLastWord("Help")
  2. Help
P.S. - Here is another alternative, but you must have at least 1 Space in the String or an Error will occur:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Mid$("<String Here>", InstrRev("<String Here>"," "))
Mar 11 '11 #3
OldBirdman
675 512MB
That will not work for Walla Walla, Port Angeles, or Saint Helens. Even the example "8235 127th St Ct E Tacoma" could be mis-parsed if E Tacoma were a city.
Mar 12 '11 #4
ADezii
8,834 Expert 8TB
@OldBirdman - There will definitely be Records that fall through the crack, but there is no method to differentiate which Strings comprise various Cities, unless of course, you incorporate some kind of Lookup Table into the Logic. A Table consisting of all City Names that consist of 2 or more syllables would do the trick.
Mar 12 '11 #5
OldBirdman
675 512MB
@ADezii - I'm not critizing your methods. I was pointing out to original poster that this, or any, function cannot determine the city name from its position in the string only.
Mar 13 '11 #6
ADezii
8,834 Expert 8TB
@OldBirdman - You are absolutely correct in your statements. This is obviously something that I should have indicated to the OP along with the Code. Thanks for catching my oversight.
Mar 13 '11 #7

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

Similar topics

6
by: Mason A. Clark | last post by:
LAST WORD(s): 1. MSIE6 and Firefox will go to the top of the page on command <a href="#top">go upsy</a> even if there is NO name="top" or id="top" They know what a "top" is :-) Opera...
3
by: ano1optimist | last post by:
I've got the code to search through a directory for word documents, open the doc, search for specific text... but I'm trying to extract data that immediately follows the selected highlighted text. ...
7
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...
2
by: teo | last post by:
I have a problem (partial). Some days ago I asked for a way to extract a word and few text around it (30 chars on the left and 30 on the right) from a long text. I went good with: ...
5
by: neobagsjol | last post by:
hi guys.. i have a problem on how to omit the last word..like for example i have this words; cafe\restaurant\hotel i would only like to view on the textbox.text the words only...
3
by: madhurchadha | last post by:
how do i remove the last word from a string in c# suppose string is "hi how are you" i wanna remove you
2
by: rajesh0303 | last post by:
I want to extract substring from string and replace them by character. .ex:In "lphrd" , I want to extract and ,and want them to replace be replaced by Ä and É. so, that the result string...
3
by: JP Romano | last post by:
Hi... I need some help with either a formula or vba routine that will extract last names for a comparison. The names can come into my spreadsheet as any of the following John Doe John J Doe Jonh...
3
by: houghi | last post by:
I have a parameter $name that contavins e.g. "Turn left at Blooming Grove Turnpike/Quassaic Turnpike/RT-94 Continue to follow RT-94". I just want to have the last word. The number of words will be...
2
by: rienh | last post by:
Hello all, I try to accomplish the following. I have a string like: “volkswagen-golf-gti” ** And I want it to change the string into: “Volkswagen Golf GTI” (last part completely uppercase) But...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.