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

Visual Basic.NETVisual C++.NETVB Script

Avatar of undefined
Last Comment
harfang
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
Avatar of kaufmed
kaufmed
Flag of United States of America image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of harfang
harfang
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of harfang
harfang
Flag of Switzerland image

> 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°)
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo