Solved

Strings and Arrays (easy 50 points)

Posted on 2001-06-21
8
152 Views
Last Modified: 2010-05-18

I have a string that is something like "AAAA 9999" and all I'm interested in is the first 4 or 5  letters, I want to split at the whitespace.  I know the split function returns an array.  Isn't there a way to convert an array into a string in one line of code instead of a loop?

Note: I can't use Left() because the letters might be longer than 4 chars in some cases.

Thanks.
0
Comment
Question by:mudface061200
8 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6215191
dim s as string
s = join(array)
this will make the array concatinated together with no spaces between then

s = Join(array,"delimiter")
will join with delimiter between words
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6215195
oops you can't leave out the delimiter to get a concatinated string

ex
s = join(array,"")
0
 
LVL 18

Expert Comment

by:deighton
ID: 6215198
sNew = left(sString,instr(sString," ")-1)
0
 
LVL 3

Accepted Solution

by:
jrspano earned 50 total points
ID: 6215204
if you want all to the space just
dim holder as variant
dim s as string
dim t as string

t = "AAAA BBBB"
holder = split(t," ")
s = holder(0)
s now has AAAA in it
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:mudface061200
ID: 6215208
jrspano,

Maybe I wasn't clear, all I want is the first sequence of letters, I don't want the numbers at all, and I surely don't want to concatenate them.  So my desired result is a string of, in this example AAAA
0
 
LVL 1

Expert Comment

by:morgan_peat
ID: 6215226
What about InStr with Left?

    sBigStr = "AAAAAA 9999"    
    sShortStr = Left$(sBigStr, InStr(sBigStr, " ") - 1)
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6215236
the instr examples above will do that, my holder example above will also give you what you want.
0
 
LVL 1

Author Comment

by:mudface061200
ID: 6215246
I thought I already tried that, but trying your example worked.  Thanks to everyone who submitted comments, jrspano was the first to respond.

Thanks again
-m
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now