|
-
Oct 16th, 2003, 02:40 PM
#1
Thread Starter
Hyperactive Member
assign a string to an array
I am looking for a fast and effeciant way of assignning a string of characters to an array.
I have tried this and it works ..
Alpha = System.Text.RegularExpressions.Regex.Split( "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", "," )
but there must be a better way. This seems very clunky.
gollnick
-
Oct 16th, 2003, 02:53 PM
#2
I'm not sure what you mean by clunky but the same function is available in the String object (but its not shared so you'll need an instance of a string)
VB Code:
Dim alpha() As String
Dim list As String = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
alpha = list.Split(",")
Or you can assign them to the array when you declare it
VB Code:
Dim alpha() As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
-
Oct 16th, 2003, 03:21 PM
#3
Thread Starter
Hyperactive Member
Ok .. but lets say the character string I get in is not comma seperated .... Just a straight datastream like...
"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
and I want this in an array where I can navigate to any single character in this string.... I cant to know that element 12 of this array is the letter "m"
gollnick
-
Oct 16th, 2003, 03:32 PM
#4
If there is no seperator then things may get more complicated. Although if you are strictly talking about chars then its even simplier than an array. A string is really just an array of chars so if the datastream is made of chars then you can assign it to a string and retrieve info vis the indexOf or SubString methods.
VB Code:
Dim datastream As String = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'get char at location 12
MsgBox(datastream.Substring(12,1))
'what index is 'm' returns -1 if not found
MsgBox(datastream.IndexOf("m"))
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|