Is this the fastest way

G

Guest

Hi,
I need to split a string by character so instead of

Dim str() as str
Dim sStr as string = "abcdef"

str(0) = sStr.substring(0,1)
str(1) = sStr.substring(1,2)
str(2) = sStr.substring(2,3)
str(3) = sStr.substring(3,4)
str(4) = sStr.substring(4,5)

I have

Dim sStr as string = "abcdef"
Dim chrs(5) as Char

sStr.CopyTo(0,chrs,0,6)

'To test
msgbox(chrs(0).toString)

Which is the better way?

Thanks
 
C

Cor Ligthert [MVP]

Chris,

Why not use that string direct as an immutable array of char

Dim sStr as string = "abcdef"
dim mychar as char = sStr(3) 'to get the d.

Cor
 
G

Guest

But then I would need to have multiple Dim statements to get the individual
values like

dim mychar as char = sStr(0)
dim mychar as char = sStr(1)
dim mychar as char = sStr(2)
dim mychar as char = sStr(3)
dim mychar as char = sStr(4)
dim mychar as char = sStr(5)

No?
 
G

Guest

Why would you put the values in separate variables? What are you going
to use it for?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top