I want to replace
| margin:100px 100px 100px 100px; |
with
| paragraphSpaceBefore: 100px; paragraphEndIndent: 100px; paragraphSpaceAfter: 100px; paragraphStartIndent: 100px; |
How can i achieve this in C#?
| margin:100px 100px 100px 100px; |
| paragraphSpaceBefore: 100px; paragraphEndIndent: 100px; paragraphSpaceAfter: 100px; paragraphStartIndent: 100px; |
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Feb 12, 2013, 5:32 AM
output = input.Replace("px", "");
Similarly, in the 'margins' example, you can simply replace this line:
string[] items = margins[i].Split(':')[1].Trim(';').Split(' ');
with this one:
string[] items = margins[i].Split(':')[1].Trim(';').Replace("px", "").Split(' ');
More generally, you can get rid of the units using regular expressions:
Salma SiddiqaPosted Feb 12, 2013, 2:17 AM
I have one more query ., how can i remove the unit from the string"font-size:0.2px"
so i need to replace "font-size:0.2px" with "font-size:0.2"
Can it be the following:
VulpesPosted Feb 8, 2013, 5:29 AM
The output should be:
Salma SiddiqaPosted Feb 8, 2013, 2:10 AM
But There can be 4 scenario:
1)
margin:25px 50px 75px 100px; //Should be converted to
paragraphSpaceBefore: 25px;
paragraphEndIndent: 50px;
paragraphSpaceAfter: 75px;
paragraphStartIndent: 100px;
2)
margin:25px 50px 75px; //Should be converted to
paragraphSpaceBefore: 25px;
paragraphEndIndent: 50px;
paragraphSpaceAfter: 75px;
3)
margin:25px 50px; //Should be converted to
paragraphSpaceBefore: 25px;
paragraphEndIndent: 50px;
4)
margin:25px; //Should be converted to
paragraphSpaceBefore: 25px;
paragraphEndIndent: 25px;
paragraphSpaceAfter: 25px;
paragraphStartIndent: 25px;
Jignesh TrivediPosted Feb 7, 2013, 10:45 PM
try...
var margin = "margin:100px 100px 100px 100px;";
var marginsplit = margin.Split(new char[] { ':' });
var valueSpilt = marginsplit[1].Split(new char[] { ' ' });
var newSting = "paragraphSpaceBefore: " + valueSpilt[0] + "; ";
newSting += "paragraphEndIndent: " + valueSpilt[1] + "; ";
newSting += "paragraphSpaceAfter: " + valueSpilt[2] + "; ";
newSting += "paragraphStartIndent: " + valueSpilt[3] ;
hope this will help you.
VulpesPosted Feb 7, 2013, 10:26 AM