0

Now I'm parsing a text, I want to split and add one by one

But first thing first, the best way is to replace multiple spaces with one unique deliminator

Below is the sample target text:

                        Total fare                         619,999.0d-
      12 11 82139     09/13/2013 D              103,500.00  2/025189 PARK LA000137
                      09/13/2013 D              50.00 File Ticket - PS1309121018882/

Can anybody know how to handle it in C#?

leppie
  • 115,091
  • 17
  • 196
  • 297
LifeScript
  • 1,116
  • 5
  • 15
  • 24

4 Answers4

1

the best way is to replace multiple spaces with one unique deliminator

Not really sure if its the best way, but following works, without REGEX

string newStr = string.Join(":", 
                str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
Habib
  • 219,104
  • 29
  • 407
  • 436
0

try

var strings = text.Split(' ').Where(str => str.Length > 0);
kwingho
  • 422
  • 2
  • 4
0

You can use a regular expression:

string delimiter = ":";
var whiteSpaceNormalised = Regex.Replace(input, @"\s+", delimiter);
Dave Bish
  • 19,263
  • 7
  • 46
  • 63
0

Use regular expressions instead, replace more than one occurrence of space with single space

string parsedText = System.Text.RegularExpressions.Regex.Replace(inputString,"[ ]+"," ");
Lav G
  • 153
  • 9