473,396 Members | 2,158 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,396 software developers and data experts.

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 1988
First thing that comes to mind is the string Split method:

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

Here is the MSDN docs and samples to do this:

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

Alex

"JeffM" <Je***@devdex.com> wrote in message
news:O1**************@TK2MSFTNGP15.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!1pnsZpX0fPvDxLKC6rAAhLsQ!352.entry

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

"JeffM" <Je***@devdex.com> wrote in message
news:O1**************@TK2MSFTNGP15.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
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!)...
1
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...
20
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...
15
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...
1
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...
11
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
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
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.