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

splitting a string out to an array of strings

Let's say I have a string sItemString = "item1~item2~item3" and a string
array asItemArray[]. In the VB world, I could use the Split function as
follows: asItemArray = Split(sItemString, "~") to split out the individual
items in the string into separate elements of the array. How could I do this
in C#?
Nov 16 '05 #1
6 1559
if you have

string sItemString = "item1~item2~item3"

try this

string[] columns = record.Split('~');

this will result in
columns[0] = item1
columns[1] = item2
columns[2] = item3

Nov 16 '05 #2
Try the String.Split() method.

--
Tim Wilson
..Net Compact Framework MVP

"BobRoyAce" <bo*@omegasoftwareinc.com> wrote in message
news:nu********************@comcast.com...
Let's say I have a string sItemString = "item1~item2~item3" and a string
array asItemArray[]. In the VB world, I could use the Split function as
follows: asItemArray = Split(sItemString, "~") to split out the individual
items in the string into separate elements of the array. How could I do this in C#?

Nov 16 '05 #3

Use the Split method.

itemArray = itemString.Split('~')

HTH,

Sam
On Mon, 21 Mar 2005 11:59:36 -0500, "BobRoyAce"
<bo*@omegasoftwareinc.com> wrote:
Let's say I have a string sItemString = "item1~item2~item3" and a string
array asItemArray[]. In the VB world, I could use the Split function as
follows: asItemArray = Split(sItemString, "~") to split out the individual
items in the string into separate elements of the array. How could I do this
in C#?


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
Nov 16 '05 #4
Sorry had the variable wrong. Try the following

if you have
string sItemString = "item1~item2~item3"
try this
string[] columns = sItemString.Split('~');
this will result in
columns[0] = item1
columns[1] = item2
columns[2] = item3

Nov 16 '05 #5
Otis Mukinfus <ot**@mukinfus.com> wrote:
string[] columns = sItemString.Split('~');


I believe the correct syntax here would be :
string[] columns = sItemString.Split(new char[] {'~'});

The Split method expects an array of char.


But the parameter has the "params" modifier, so the two lines of code
above are equivalent.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
It works even with '~'. I have a working code which does the following

string[] columns = record.Split('~')

Nov 17 '05 #7

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

Similar topics

26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i don´t have a lot of success. Can anybody help me (and understand my english :-))? I have a...
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!)...
7
by: Mad Scientist Jr | last post by:
I have been doing this kind of thing in VB and VB.net for a long time, but am having problems in C#: First I want to split up a string by the backslash character, but this line: arrSplit =...
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
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...
12
by: Simon | last post by:
Well, the title's pretty descriptive; how would I be able to take a line of input like this: getline(cin,mostrecentline); And split into an (flexible) array of strings. For example: "do this...
13
by: Pedro Pinto | last post by:
Hi there. I'm trying to do the following. I have a string, and i want to separate it into other halves. This is how it should be: char string = "test//test2//test3"; were // is the part...
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
4
by: r035198x | last post by:
Breaking up a string Instead of using the old StringTokenizer class, a simple trick is to use the String.split method. String string = "This is a string"; String tokens = string.split("...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: 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: 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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.