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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 7, 2013, 5:26 AM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 7, 2013, 5:45 PM EST
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.
Salma Siddiqa11 reputationPosted Feb 7, 2013, 9:10 PM EST
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;
VulpesRank #55 · 29.2K reputationPosted Feb 8, 2013, 12:29 AM EST
The output should be:
Salma Siddiqa11 reputationPosted Feb 11, 2013, 9:17 PM EST
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:
VulpesRank #55 · 29.2K reputationPosted Feb 12, 2013, 12:32 AM EST
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: