Solved

Need to parse a string and replace two values

Posted on 2008-10-10
3
580 Views
Last Modified: 2013-12-17
I am retrieving data from an XML web service, and one piece is a bit of HTML that embeds a flash object on the page.  I simply output this HTML onto the page, and presto - it shows.

In the embedded data is a width and height, that I want to modify by a factor of 1.5 or 2.  Ie:

<embed wmode=opaque src="{source}" quality=high width=" 600" height=" 528">

I want to retrieve the width and height, and multiply it by a factor, and replace the values before outputting it on the page to artificially enlarge the flash object.

How can I do that in ASP.NET V3.5 C#?
0
Comment
Question by:adworldmedia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 22692460
Import System.Text.RegularExpressions (with "using"), the you can use something like this....


    string patt = "(.*?)width\\=\\\"\\s(\\d+)\\\"\\sheight\\=\\\"\\s(\\d+)\\\"(.*?)";
    Match RegM = Regex.Match(OldString, patt);
    
    string NewString = (Regex.Replace(TextBox1.Text, patt, "$1width=\"" + RegM.Groups(2).Value * 2 + "\" height=\"" + RegM.Groups(3).Value * 2 + "\"$4"));

Open in new window

0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22696173
Other method is by the way of Xml if you are able to load you string to an Xml

XmlDocument doc = new XmlDocument();
doc.LoadXml ("<embed wmode=\"opaque\" src=\"{source}\" quality=\"high\" width=\"600\" height=\"528\" />");
doc.SelectSingleNode("//embed").Attributes.GetNamedItem("width").Value = (2 * Convert.ToInt32(doc.SelectSingleNode("//embed").Attributes.GetNamedItem("width").Value)).ToString();
doc.SelectSingleNode ("//embed").Attributes.GetNamedItem ("height").Value = (2 * Convert.ToInt32 (doc.SelectSingleNode ("//embed").Attributes.GetNamedItem ("height").Value)).ToString ();
string abc = doc.OuterXml;
0
 

Author Closing Comment

by:adworldmedia
ID: 31505188
I had to change the Textbox1.text to the oldstring, and the RegM.Groups(x) to RegM.Groups[x] then it worked like a charm!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question