Is this the fastest way

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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?
 
Back
Top