33

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

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Jamie
  • 525
  • 2
  • 8
  • 12

3 Answers3

54

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

juan
  • 80,295
  • 52
  • 162
  • 195
4

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

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

Damith
  • 62,401
  • 13
  • 102
  • 153
The Evil Greebo
  • 7,013
  • 3
  • 28
  • 55
1

This is one way

"hello#world".Split('#');
Damith
  • 62,401
  • 13
  • 102
  • 153
Mike
  • 5,918
  • 9
  • 57
  • 94