473,903 Members | 4,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Splitting a string array to seperate variables

Quick C# question:
I have comma delimited values in a string array that I want to pass to
seperate variables. Any tips on splitting the array?

Thanks in advance!

JM

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
4 2027
First thing that comes to mind is the string Split method:

string csv = "1,2,3,4";
string [] numbers = csv.Split(",".T oCharArray());

Here is the MSDN docs and samples to do this:

http://msdn.microsoft.com/library/de...splittopic.asp

Alex

"JeffM" <Je***@devdex.c om> wrote in message
news:O1******** ******@TK2MSFTN GP15.phx.gbl...
Quick C# question:
I have comma delimited values in a string array that I want to pass to
seperate variables. Any tips on splitting the array?

Thanks in advance!

JM

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2
If you also want to split quoted fields and/or ignore multiple delim in a
row, check out:
http://spaces.msn.com/members/staceyw/Blog/cns!1pnsZpX0fPv DxLKC6rAAhLsQ!3 52.entry

--
William Stacey, MVP
http://mvp.support.microsoft.com

"JeffM" <Je***@devdex.c om> wrote in message
news:O1******** ******@TK2MSFTN GP15.phx.gbl...
Quick C# question:
I have comma delimited values in a string array that I want to pass to
seperate variables. Any tips on splitting the array?

Thanks in advance!

JM

*** Sent via Developersdex http://www.developersdex.com ***


Nov 17 '05 #3

Thanks Alex!
Just what I was looking for-

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #4
Wow, that's a pretty cool script.
Although I am generating test files out of Excel, so spacing and
formatting should be OK, this is very nice to allow commas in the input
string itself.
Thanks much :-)

JM

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5

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

Similar topics

5
2979
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!) printing the results I expect, which I guess means my dynamic memory allocation is a mess. Also, I was advised previously that I should really free memory in the same place I declare it, but I'm not sure how I would go about doing this in my code...
1
1712
by: Justin | last post by:
I have a string of dates seperated by commas and I need to seperate them and put them into a dropdown control. With the code below I am able to only remove the comma which results in one big long string with no spaces and the string is listed 5 time. How can I seperate the dates into seperate strings. Here is the code I have so far: string strDelim = ","; char charDelim = strDelim.ToCharArray(); string Dates = StartDate;
20
3729
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up the data to assign each value to its own variable. So right now I am just saving the data to a txt file and when I look in the text file all the data is there. Not sure if this matters but when I open the text file in Word pad (Rich Text) It...
15
16368
by: Daren | last post by:
Hi, I need to be able to split large string variables into an array of lines, each line can be no longer than 70 chars. The string variables are text, so I would additionally like the lines to end at the end of a word, if you catch my drift. For example, I have a large string variable containing the text: "I've seen things you people wouldn't believe. Attack ships on fire
1
1378
by: Gustav | last post by:
Hi! I use a regex (?<!\\?)('|\\+|:) to split a string to a String. The String i get after splitting is correctly splitted but contains all the delimiters i use to decide where the string should be splitted. Do I have to loop through the array and find every index containing a single delimiter or is there a easier way to do this.
11
6694
by: monomaniac21 | last post by:
hi all is there a function to convert all values of array $row into seperate variables: $row = mysql_fetch_array($result); // i dont want to have to do this anymore :-) $name = $row;
12
3053
by: John | last post by:
Hi I have a multi-line address field which has each line separated by CRLF. How can I split this field into individual strings using crlf as separator? Thanks Regards
12
1937
by: kevineller794 | last post by:
I want to make a split string function, but it's getting complicated. What I want to do is make a function with a String, BeginStr and an EndStr variable, and I want it to return it in a char array. For example: char teststr; strcpy(teststr, "test:blah;");
0
9999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11283
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10875
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10986
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7206
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6093
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4308
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3324
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.