Solved

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

Posted on 2014-09-10
2
168 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
2 Comments
 
LVL 33

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

808 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