Solved

Need to parse a string and replace two values

Posted on 2008-10-10
3
576 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

Industry Leaders: 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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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