473,378 Members | 1,334 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,378 software developers and data experts.

help with selecting first 2 letters in string

I have a string surname and want to select the first two letters to
use in a code field
how can i check if the second item in string is an apostrophe and
filter it out ' in names such as o'brien and use the third item in
string so i get ob

in other words if surname = brown code =br
but if surname = o'brien code = ob

colm
Nov 13 '05 #1
2 2741
Something like the following untested air-code should work:

Function ReturnLetters(InputName As String) As String

Dim intLoop As Integer
Dim intSelected As Integer
Dim strCurrLetter As String
Dim strCode As String

For intLoop = 1 to Len(InputName)
strCurrLetter = Mid(InputName, intLoop, 1)
If (strCurrLetter >= "a" And strCurrLetter <= "z") Or _
(strCurrLetter >= "A" And strCurrLetter <= "Z")
strCode = strCode & strCurrLetter
intSelected = intSelected + 1
If intSelected = 2 Then
Exit For
End If
End If
Next intLoop

ReturnLetters = strCode

End Function

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"colm" <cobrien@don'tsendmespam.btinternet.com> wrote in message
news:mh********************************@4ax.com...
I have a string surname and want to select the first two letters to
use in a code field
how can i check if the second item in string is an apostrophe and
filter it out ' in names such as o'brien and use the third item in
string so i get ob

in other words if surname = brown code =br
but if surname = o'brien code = ob

colm

Nov 13 '05 #2
On Tue, 26 Oct 2004 21:52:07 +0000 (UTC), colm wrote:
I have a string surname and want to select the first two letters to
use in a code field
how can i check if the second item in string is an apostrophe and
filter it out ' in names such as o'brien and use the third item in
string so i get ob

in other words if surname = brown code =br
but if surname = o'brien code = ob

colm


=IIf(Mid([LastName],2,1)="'",Left([LastName],1) &
Mid([LastName],3,1),Left([LastName],2))

--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jester.dev | last post by:
Hello, I'm learning Python from Python Bible, and having some problems with this code below. When I run it, I get nothing. It should open the file poem.txt (which exists in the current...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
4
by: ollie.mitch | last post by:
Hi, I need two ereg expressions in my PHP code. One of them needs to check that a string only contains letters, and the other needs to check that the string only contains letters and commas...
1
hpbutterbeer
by: hpbutterbeer | last post by:
We have a Machine Project and my brain is currently in a clouded state. Sorry, I'm just a beginner in C Programming... Text twist is a windows game whose main objective is to form words out of the...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
3
NewYorker
by: NewYorker | last post by:
Hello brothers and sisters, Please help me complete this program and get the output shown below. Here is all I have ___________________________________________________________ This...
2
by: theronnightstar | last post by:
I am writing an anagram program for my fiance. Figured it would be an excellent task to learn from. The way it is supposed to work is it reads in a word list from a file into a temporary...
0
by: yabighelen | last post by:
HELP!!!!! I have to write a program that does this: Create a program that encrypts and decrypts a message... Inputs: A typed message Output: When the encrypt button is clicked the input...
9
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.