Solved

Need to parse a string and replace two values

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now