Solved

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

Posted on 2014-09-10
2
170 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

734 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