Solved

Need to parse a string and replace two values

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

9 Experts available now in Live!

Get 1:1 Help Now