Solved

How do I parse some Javascript in Asp.net c#

Posted on 2014-09-10
2
171 Views
Last Modified: 2014-09-26
I have some Javascript stored, that I want to be able to extract the location= value, which is a URL.

The string is something like:

<script>window.location='http://www.expert-exchange.com'</script>

Open in new window


How would one do this?
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
2 Comments
 
LVL 34

Expert Comment

by:ste5an
ID: 40314354
Use an appropriate regulare expression with the Regex Class.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40314824
You can use a regex, but a simple substring search should suffice.

e.g.

string source = "<script>window.location='http://www.expert-exchange.com'</script>";
int startingQuoteIndex = source.IndexOf("'");
int endingQuoteIndex = source.IndexOf("'", startingQuoteIndex + 1);
string url = source.Substring(startingQuoteIndex + 1, endingQuoteIndex - startingQuoteIndex);

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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