Solved

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

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

Expert Comment

by:Stefan Hoffmann
Comment Utility
Use an appropriate regulare expression with the Regex Class.
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now