?
Solved

Need to parse a string and replace two values

Posted on 2008-10-10
3
Medium Priority
?
582 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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