Solved

Strings and Arrays (easy 50 points)

Posted on 2001-06-21
8
151 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 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

22 Experts available now in Live!

Get 1:1 Help Now