Link to home
Create AccountLog in
Avatar of shilpi2
shilpi2

asked on

Splitting when space

Hi Experts,

I have an array and I am looping the array. Each row of the array will have an entry like A B .I want to split the record when I come across the first space and store it in another variable. How do I achieve it. I am unable to do this with split function.

Thanks

Shilpi
Dim m As Long
    m = 0
    Do Until IsEmpty(varArray3)
    Dim Portfolio As String
    Portfolio = Split(varArray3(m), " ")(0)
    Loop

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Is it a hard space?

Portfolio = Split(replace(varArray3(m), chr(160), " "), " ")(0)

Chris
Is this VB.NET or VBScript?
Avatar of shilpi2
shilpi2

ASKER

I get subscript out of range error. The space just spearates 2 words. There is no limit to the length of a word.
Thanks
If it isn't a hard space then what is it ...

when it 'breaks on the error, type the string into the immediate window ... ctrl + G to display it

Now find where you think the space is in the word and type into the immediate window:


?asc(mid(varArray3(m), 5))

replace 5 with the character position of the space ... what do you get?


Chris
?varArray3(m)

will display the actual string

Chris
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
> I get subscript out of range error.

That can happen because varArray3(0) is out of range (or the array isn't dimensioned), or because varArray3(m) is an empty string. Split("") returns an array with -1 as upper bound.

(°v°)