|
-
Sep 19th, 2013, 11:59 AM
#1
Thread Starter
Hyperactive Member
String to Array
Hi,
Im kinda stuck on a thing ...
Im having a var containing a string :
Code:
Dim Categ As String = "Rugby,NFL,Football,ecc"
What i need to do is to add the string from Categ string in each separate array :
my.categories = {"Rugby", "NFL", "Football", "ecc"}
Is there a way of doing this having in mind that some times Categ could have only 2 words, sometimes 10 words...
Any help would be greately appreciated...
Cheers!
Thanks for helping me out.
-
Sep 19th, 2013, 12:11 PM
#2
Re: String to Array
Well you could start with this:-
vbnet Code:
'
Dim Categ As String = "Rugby,NFL,Football,ecc"
Dim CategArray As String() = Categ.Split(","c)
The above separates each of the sports into separate elements in one array.
-
Sep 19th, 2013, 12:16 PM
#3
Thread Starter
Hyperactive Member
Re: String to Array
Yes, thanks.
And then getting the data back with :
String.Join(", ", CategArray.ToArray)
Now the main problem remains how to add all the random arrays into this shape :
my.categories = {"Rugby", "NFL", "Football", "ecc"}
or
my.categories = {"Rugby", "NFL", "Football", "Soccer", "Cricket"}
This is what confuses me the most
Thanks for helping me out.
-
Sep 19th, 2013, 12:23 PM
#4
Re: String to Array
You've lost me. What random arrays ? What shape ?
-
Sep 19th, 2013, 12:28 PM
#5
Thread Starter
Hyperactive Member
Re: String to Array
dim c as string = "Rugby,NFL,Football,ecc" ' could have more words ... one, two, twenty, ecc
Dim Categ As String = c
so now i need to split the Categ string into arrays and then put them in the following code ... depending on how many words i have to put:
my.categories = {"Rugby", "NFL", "Football", "ecc"}
Sometimes it could be :
dim c as string = "Rugby,NFL,Football,Soccer,Cricket"
Dim Categ As String = c
my.categories = {"Rugby", "NFL", "Football", "Soccer", "Cricket"}
Thanks for helping me out.
-
Sep 19th, 2013, 05:15 PM
#6
Re: String to Array
 Originally Posted by Niya
You've lost me.
this
What are you trying to do? Maybe start by explaining that.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Sep 19th, 2013, 08:31 PM
#7
Re: String to Array
Yeah, that isn't any more clear. If my.categories is an array, then there isn't much point of breaking it up the way you are, since Split is already giving you an array. The {} notation is just a way to initialize an array with a set of values, but since you already have the array from Split, you don't need to initialize it.
My usual boring signature: Nothing
 
-
Sep 24th, 2013, 12:40 PM
#8
Thread Starter
Hyperactive Member
Re: String to Array
maybe in the something like this but in vbnet:
Code:
$content['custom_fields'] = array(
array('key' => 'cricket', 'value' => true),
array('key' => 'football', 'value' => true),
array('key' => 'soccer', 'value' => true),
);
Thanks for helping me out.
-
Sep 24th, 2013, 12:51 PM
#9
Re: String to Array
Does your brain comprehend we have no idea what my.categories even is? at what point has this entered our lives. You might get some solid help if you actually took the time to explain in DETAIL.
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
|