Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Strings and Arrays (easy 50 points)

Posted on 2001-06-21
8
Medium Priority
?
163 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
jrspano earned 200 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
 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

916 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