473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Populate Array

Hi All,

I have a string which has product names, which are seperated by comma. The
number of products in the string are random.
I want to populate the array using the string, one product per level.

Please let me know how to do it.

Thanks in Advance,
Anil
Nov 16 '05 #1
2 6534

Have a look at the documentation for String.Split


"Anil" <an******@yahoo.com> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have a string which has product names, which are seperated by comma. The
number of products in the string are random.
I want to populate the array using the string, one product per level.

Please let me know how to do it.

Thanks in Advance,
Anil

Nov 16 '05 #2
Anil,

Try this out.

// generate a random comma-delimited string for your product names
const string randChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ";
Random r = new Random();

const string delimiters = ","; // characters that count as delimiters
int maxNames = 10; // maximum number of random names to generate
int maxLength = 32; // maximum length of characters in random name string

System.Text.StringBuilder sb = new System.Text.StringBuilder();

// O(maxNames * maxLength) loop to generate names
for (int i = 0; i < r.Next(maxNames+1); i++)
{
// generate a name by picking one character at a time
for (int j = 0; j < r.Next(maxLength+1); j++)
{
// append a random alphabetic character to the end of the current name
sb.Append(randChars.Substring(r.Next(randChars.Len gth), 1));
}
// append a random delimiter character to the end and start a new name
sb.Append(delimiters.Substring(r.Next(delimiters.L ength), 1));
}

// get the product names into a string array
string[] prodNames = sb.ToString().Split(delimiters.ToCharArray());

// print the product names
foreach (string s in prodNames)
{
Console.WriteLine("Product name found: {0}", s);
}
I have a string which has product names, which are seperated by comma. The
number of products in the string are random.
You can see that the number of products is indeterminate at compile-time
(it's random!), so this solution should work in general if you want to test
the Split method out on random product names. The Split method is what you
want to use here to get the individual strings.

Best wishes,
JJ Feminella

"Anil" <an******@yahoo.com> wrote in message
news:uO**************@TK2MSFTNGP10.phx.gbl... Hi All,

I have a string which has product names, which are seperated by comma. The
number of products in the string are random.
I want to populate the array using the string, one product per level.

Please let me know how to do it.

Thanks in Advance,
Anil

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
10
by: Craig Keightley | last post by:
I have the following array: function showCPUs(){ //name brandID dualCore dualProcessor var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=;
4
by: Kevin H | last post by:
Apologies in advance if this sounds slow-witted, but I didn't find it here. Need to populate some textboxes on a form. While I could hard code it (the number of options aren't that high), it...
2
by: George | last post by:
Is there a fast way to transfer an Excel range to an array? Example: Excel range is E2:E300 Dim person() as string Thanks, George
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
3
by: OliveOyl3471 | last post by:
In Visual Basic.NET 2003, how do you populate a two dimensional array from a text file? I know how to check file existence, open the file for read, etc. I just can't get it to read more than one...
1
by: DavidPr | last post by:
I have a website that requires a visitor to register in order to make a post. I have one or two users that are violating the terms and every day I'm having to delete them. They just re-register,...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.