1

I have a string like 1ADFGRE#34GGGHT#04RTYHGR.

I want to extract words from this by eliminating #.

like:

a = 1ADFGRE
b = 34GGGHT
c = 04RTYHGR
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Laxminarayan
  • 95
  • 3
  • 7

3 Answers3

7

Use String.Split(Char()), Like this:

yourString = "1ADFGRE#34GGGHT#04RTYHGR";
string[] words = yourString.Split('#'); 

The array words will contain something like:

1ADFGRE
34GGGHT
04RTYHGR
Mahmoud Gamal
  • 75,299
  • 16
  • 132
  • 159
3

The easiest way would be to use code like this:

string[] splitString = "1ADFGRE#34GGGHT#04RTYHGR".Split('#')
gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355
Simon Smeets
  • 573
  • 6
  • 17
0

You can also use regular expressions to split up strings. Regex.Split will provide more flexibility if you have to split up on more complicated strings. There is a good discussion in this article: String.Split VS. Regex.Split?

string[] matches = Regex.Split(yourString, @"#");
Community
  • 1
  • 1
Rob4md
  • 194
  • 4