Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-09-10
2
Medium Priority
?
174 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 35

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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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