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
  • 112,162
  • 17
  • 191
  • 293
LifeScript
  • 1,086
  • 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
  • 212,447
  • 27
  • 392
  • 421
0

try

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

You can use a regular expression:

string delimiter = ":";
var whiteSpaceNormalised = Regex.Replace(input, @"\s+", delimiter);
Dave Bish
  • 18,741
  • 7
  • 42
  • 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