Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to serializer/Make an array from string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to serializer/Make an array from string

    I have a web-app, that can return arrays in output, like :

    Code:
    a:1:{i:0;s:12:"My_Colleague1";}
    or

    Code:
    array("key"=>"value");
    (or I can output it as it is recomended,in XML or what you tell me)

    then i get that response as string in NinjaScript.
    but how to convert that into NinjaScript acceptable array/object?
    Last edited by ttodua; 08-20-2017, 05:34 AM.

    #2
    Hello selnomeria,

    As a heads up, this would fall under general C# education and would not be specific to NinjaScript.

    As a tip, you can use string.Split() to separate a string to an array by a delimiter.
    Use the string.Split method. Call Split with arguments to separate on newlines, spaces and words.


    If it is a custom string, you may need to use substring or regular expressions and build the array yourself.
    Get parts from existing strings with Substring. Pass start and length arguments.

    Use the Regex class and Regex.Match, reviewing features from System.Text.RegularExpressions.

    Create and loop over a string array. Access array Length and get elements at indexes.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Assuming your array is an array of strings...


      using (var stream = File.Create("file.xml")) {
      var serializer = new XmlSerializer(typeof(string[]));
      serializer.Serialize(stream, someArrayOfStrings);
      }

      Will create a simple XML file that is very easy to understand/modify. To deserialize it, use the Deserialize method.

      http://csharp.net-informations.com/c...harp-array.htm

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Kaledus, Today, 01:29 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frankthearm, Yesterday, 09:08 AM
      13 responses
      45 views
      0 likes
      Last Post frankthearm  
      Started by PaulMohn, Today, 12:36 PM
      2 responses
      16 views
      0 likes
      Last Post PaulMohn  
      Started by Conceptzx, 10-11-2022, 06:38 AM
      2 responses
      55 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Started by yertle, Yesterday, 08:38 AM
      8 responses
      37 views
      0 likes
      Last Post ryjoga
      by ryjoga
       
      Working...
      X