Solved

Strings and Arrays (easy 50 points)

Posted on 2001-06-21
8
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 7 hours left to enroll

636 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