3

I have this in my SVG file:

d="
m49.84965,40.23129
l99.5682,19.94812
l0.2192,100.11412
l-100.78656,-19.99842
z"

I want to have rounded coordinates:

d="
m50,40
l100,20
l0,100
l-100,-20
z"/>

The entire document is much larger. I used regex to erase the decimals, which are lower then 5:

\.[01234]\d*

But with rounding higher decimals I had much more work:

0\.[56789]\d* ;replace with: 1
1\.[56789]\d* ;replace with: 2
2\. ...

It began to be complicated, when I had to deal with numbers like this one: -19.99842

How do I handle this?

Kardaw
  • 371
  • 2
  • 14
  • 1
    I'm not sure that regex really makes sense for the rounding portion of this... it might make more sense to write a small c program, or the like, to read in the file and do the rounding there... – user3334690 Apr 28 '14 at 15:32
  • I only used the replace box in Notepad++: [PICTURE](http://appdevonsharepoint.com/wp-content/uploads/2013/10/RegExFind.png) It isn't possible to increment numbers with this, isn't it? – Kardaw Apr 28 '14 at 15:33
  • I understand what you are doing... I just think it may not be sufficient/convenient to do what you want... – user3334690 Apr 28 '14 at 15:35
  • possible duplicate of [Rounding using regular expressions](http://stackoverflow.com/questions/7584113/rounding-using-regular-expressions) – user3334690 Apr 28 '14 at 15:41
  • Also I feel compelled to point out that truncating numbers like this could significantly impact the layout of the objects in your document. Especially, for instance, if the viewBox size is small, or your document uses coordinates in the objectBoundingBox space. – Paul LeBeau Apr 28 '14 at 19:04

1 Answers1

2

Not sure that can be done just in Notepad++, I would use Powershell. That way you can mix regex and numeric functions. Something like this:

gc YourFileName | % {$l = $_; [regex]::Matches($_, '[\d.]+') | % {
$l = $l -Replace $_.Value, ([Int32]$_.Value).ToString()}; $l} | Out-File YourNewFileName
Dave Sexton
  • 10,768
  • 3
  • 42
  • 56