Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String Manipulation using Split Method

Tags:

string

c#

split

I having a problem on using Split Method().

I have a string like this:

string diagnosis = "001.00 00 002.01 00 003.00 01";

And output should be:

001.00
002.01
003.00

I tried in this two ways to remove the two digits:

1

    string[] DiagnosisCodesParts = diagnosis.Split();
    if (DiagnosisCodesParts[x].Length > 3)
       {
         //here
       }

And..

2

string DiagnosisCodestemp = diagnosis.Replace(" 00 ", " ").Replace(" 01 ", " ").Replace(" 02 ", " ") 

Is there other way to remove the two digits?

like image 807
im useless Avatar asked Dec 09 '22 04:12

im useless


1 Answers

Clearest to me would be

Regex.Matches(diagnosis, @"\d+\.\d+").Cast<Match>().Select(m => m.Value);
like image 57
mqp Avatar answered Dec 23 '22 04:12

mqp