Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Splitting Strings?

Tags:

string

c#

split

just wondering for example, if I had the string:

Hello#World#Test

How would I remove the # and then have Hello, World and Test in three seperate strings, for example called: String1 and String2 and String3

like image 962
Jamie Avatar asked Sep 26 '11 17:09

Jamie


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C full form?

Full form of C is “COMPILE”. One thing which was missing in C language was further added to C++ that is 'the concept of CLASSES'.


2 Answers

You can have them in an array of strings doing something as easy as this:

string[] s = "Hello#World".Split('#'); 

s[0] contains "Hello", and s[1] contains "World"

See here for more information on split: http://msdn.microsoft.com/en-us/library/b873y76a.aspx

like image 99
juan Avatar answered Oct 06 '22 08:10

juan


String.Split("#".ToCharArray()) will return a string[] with two elements.

Element0 will be "Hello", and Element1 will be "World"

like image 22
The Evil Greebo Avatar answered Oct 06 '22 09:10

The Evil Greebo