Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 963715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:42:50+00:00 2026-05-16T01:42:50+00:00

Hey. I have this javascript file that I’m getting off the web and it

  • 0

Hey. I have this javascript file that I’m getting off the web and it consists of basically several large javascript arrays. Since I’m a .net developer I’d like for this array to be accessible through c# so I’m wondering if there are any codeplex contributions or any other methods that I could use to turn the javascript array into a c# array that I could work with from my c# code.

like:

var roomarray = new Array(194);
var modulearray = new Array(2055);
var progarray = new Array(160);
var staffarray = new Array(3040);
var studsetarray = new Array(3221);

 function PopulateFilter(strZoneOrDept, cbxFilter) {
    var deptarray = new Array(111);
    for (var i=0; i<deptarray.length; i++) {
        deptarray[i] = new Array(1);
    }
    deptarray[0] [0] = "a/MPG - Master of Public Governance";
    deptarray[0] [1] = "a/MPG - Master of Public Governance";
    deptarray[1] [0] = "a/MBA_Flex MBA 1";
    deptarray[1] [1] = "a/MBA_Flex MBA 1";
    deptarray[2] [0] = "a/MBA_Flex MBA 2";
    deptarray[2] [1] = "a/MBA_Flex MBA 2";
    deptarray[3] [0] = "a/cand.oecon";
    deptarray[3] [1] = "a/cand.oecon";

and so forth

This is what I’m thinking after overlooking the suggestions:

  1. Retrieve the javascript file in my c# code by making an httprequest for it

  2. paste it together with some code i made myself

  3. from c# call an execute on a javascript function selfmade function that will turn the javascript array into json (with help from json.org/json2.js), and output it to a new file

  4. retrieve the new file in c# parsing the json with the DataContractJsonSerializer resulting hopefully resulting in a c# array

does it sound doable to you guys?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:42:50+00:00Added an answer on May 16, 2026 at 1:42 am

    I’m not in front of a computer with c# right now so I’m not able to fully try this.

    What you’re going to need to do @Jakob is the following:

    1. Write a parser that will download the file and store it in memory.
    2. For each section that you want to “parse” into a c# array (for example zonearray), you need to setup bounds to begin searching and end searching the file. Example: We know that zonearray starts building the array the two lines after zonearray[i] = new Array(1); and ends on zonearray.sort().
    3. So with these bounds we can then zip through each line between and parse a C# array. This is simple enough I think that you can figure out. You’ll need to keep track of sub-index as well remember.
    4. Repeat this 2-3 for each array you want to parse (zonearray, roomarray..etc).

    If you can’t quite figure out how to code the bounds or how to parse the line and dump them into arrays, I might be able to write something tomorrow (even though it’s a holiday here in Canada).

    EDIT: It should be noted that you can’t use some JSON parser for this; you have to write your own. It’s not really that difficult to do, you just need to break it into small steps (first figure out how to zip through each line and find the right “bounds”).

    HTH

    EDIT: I just spent ~20 minutes writing this up for you. It should parse the file and load each array into a List<string[]>. I’ve heavily commented it so you can see what’s going on. If you have any questions, don’t hesitate to ask. Cheers!

    private class SearchBound
    {
        public string ArrayName { get; set; }
        public int SubArrayLength { get; set; }
        public string StartBound { get; set; }
        public int StartOffset { get; set; }
        public string EndBound { get; set; }
    }
    
    public static void Main(string[] args)
    {
        //
        // NOTE: I used FireFox to determine the encoding that was used.
        // 
    
        List<string> lines = new List<string>();
    
        // Step 1 - Download the file and dump all the lines of the file to the list.
        var request = WebRequest.Create("http://skema.ku.dk/life1011/js/filter.js");
        using (var response = request.GetResponse())
        using(var stream = response.GetResponseStream())
        using(var reader = new StreamReader(stream, Encoding.GetEncoding("ISO-8859-1")))
        {
            string line = null;
    
            while ((line = reader.ReadLine()) != null)
            {
                lines.Add(line.Trim());
            }
    
            Console.WriteLine("Download Complete.");
    
        }
    
        var deptArrayBounds = new SearchBound
        {
            ArrayName = "deptarray",                    // The name of the JS array.
            SubArrayLength = 2,                         // In the JS, the sub array is defined as "new Array(X)" and should always be X+1 here.
            StartBound = "deptarray[i] = new Array(1);",// The line that should *start* searching for the array values.
            StartOffset = 1,                            // The StartBound + some number line to start searching the array values.
                                                        // For example: the next line might be a '}' so we'd want to skip that line.
            EndBound = "deptarray.sort();"              // The line to stop searching.
        };
    
        var zoneArrayBounds = new SearchBound
        {
            ArrayName = "zonearray",
            SubArrayLength = 2,
            StartBound = "zonearray[i] = new Array(1);",
            StartOffset = 1,
            EndBound = "zonearray.sort();"
        };
    
        var staffArrayBounds = new SearchBound
        {
            ArrayName = "staffarray",
            SubArrayLength = 3,
            StartBound = "staffarray[i] = new Array(2);",
            StartOffset = 1,
            EndBound = "staffarray.sort();"
        };
    
        List<string[]> deptArray = GetArrayValues(lines, deptArrayBounds);
        List<string[]> zoneArray = GetArrayValues(lines, zoneArrayBounds);
        List<string[]> staffArray = GetArrayValues(lines, staffArrayBounds);
        // ... and so on ...
    
        // You can then use deptArray, zoneArray etc where you want...
    
        Console.WriteLine("Depts: " + deptArray.Count);
        Console.WriteLine("Zones: " + zoneArray.Count);
        Console.WriteLine("Staff: " + staffArray.Count);
        Console.ReadKey();
    
    }
    
    private static List<string[]> GetArrayValues(List<string> lines, SearchBound bound)
    {
        List<string[]> values = new List<string[]>();
    
        // Get the enumerator for the lines.
        var enumerator = lines.GetEnumerator();
    
        string line = null;
    
        // Step 1 - Find the starting bound line.
        while (enumerator.MoveNext() && (line = enumerator.Current) != bound.StartBound)
        {
            // Continue looping until we've found the start bound.
        }
    
        // Step 2 - Skip to the right offset (maybe skip a line that has a '}' ).
        for (int i = 0; i <= bound.StartOffset; i++)
        {
            enumerator.MoveNext();
        }
    
        // Step 3 - Read each line of the array.
        while ((line = enumerator.Current) != bound.EndBound)
        {
    
            string[] subArray = new string[bound.SubArrayLength];
    
            // Read each sub-array value.
            for (int i = 0; i < bound.SubArrayLength; i++)
            {
    
                // Matches everything that is between an equal sign then the value 
                // wrapped in quotes ending with a semi-colon.
                var m = Regex.Matches(line, "^(.* = \")(.*)(\";)$");
    
                // Get the matched value.
                subArray[i] = m[0].Groups[2].Value;
    
                // Move to the next sub-item if not the last sub-item.
                if (i < bound.SubArrayLength - 1)
                {
                    enumerator.MoveNext();
                    line = enumerator.Current;
                }
            }
    
            // Add the sub-array to the list of values.
            values.Add(subArray);
    
            // Move to the next line.
            if (!enumerator.MoveNext())
            {
                break;
            }
        }
    
        return values;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all, I'm about to rip my hair out. I have this client that
Hey this is the weirdest problem i've ever encoutered, I have 2 projects that's
Hey guys I simply cannot get this to work. I have some content that
Hey I have this little javascript bookmark javascript:(function(){ window.open('http://www.mywebsite.com/index.php?currentsite#bookmark'); })() How can I get
Hey guys, I have this piece of jquery code: <script type=text/javascript > $(function() {
I have this code that executes a for loop in javascript with a php
Hey I have this code right here: http://pastie.org/534470 And on line 109 I get
Hey I have this code but it doesn't work because it is expecting a
hey guys having this really simple problem but cant seem to figure out have
Hey this might be a simple question, but i have been stumped on it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.