Split data with regex into class of properties with C# and Regex -


so have data this:

((4886.03 12494.89 "lyr3_sig2")) 

it going space delimited want use regex place each property.

yes, playing around regex

string q = "4886.03 12494.89 \"lyr3_sig2"; string clean = regex.replace(q, @"[^\w\s]", string.empty); 

but aim put each of 3 values class this

public class bowties {     public double xcoordinate { get; set; }     public double ycoordinate { get; set; }     public string layer { get; set; } } 

now parsing data property

t = streamreader.readline(); if ((t != null) && regex.ismatch(t, "(\\(\\()[a-za-z_,\\s\".0-9-]{1,}(\"\\)\\))"))    currentviotype.bowtie = new parsetype() { formatted = regex.match(t, "(\\(\\()[a-za-z_,\\s\".0-9-]{1,}(\"\\)\\))").value.trim('(', ')'), original = t }; 

but want put data doubles , string data space delimited ((4886.03 12494.89 "lyr3_sig2")) started down path of refactoring , temporarily not using regex getting doubles ( going first 2 values, followed string started doing this:

currentaddpla.bows.add(new bowties() { xcoordinate = 44.33, ycoordinate = 344.33, layer = regex.match(t, "(\\(\\()[a-za-z_,\\s\".0-9-]{1,}(\"\\)\\))").value.trim('(', ')')}); 

but need use regex , parse dumping first value (the double xcoordinate, 2nd value ycoordinate , 3rd value regex getting data , needs 3rd value of "lyr3_sig2" should found regex right?

it going space delimited thus

regex sounds overkill. have considered using string.split(' ');, eg:

string s = "((4886.03 12494.89 \"lyr3_sig2\"))"; s = s.replace("(", string.empty).replace(")", string.empty); string[] arr = s.split(' ');  currentaddpla.bows.add(new bowties() {     xcoordinate = convert.todouble(arr[0]),    ycoordinate = convert.todouble(arr[1]),    layer = arr[3]}); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -