0

how would I convert this c# code to javascript to accomplish the same thing.

var s = styles.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); 

    1 Answer 1

    2

    If styles is a string, it's as simple as:

    styles.split(/[\r|\r\n]/); 

    var styles = 'body {font-size: 12px;}\n\ .someClass {color: red}'; document.querySelector('#result').textContent = '[' + (styles.split(/[\r|\r\n]/)) +']';
    <pre id="result"></pre>

    3
    • I am trying to split the array at the comma. this didn't seem to work.CommentedFeb 26, 2016 at 15:15
    • i am trying to change this: var s = style.split(/\r\n|\r/); return manager.executeQuery(breeze.EntityQuery.from("Orders").where("ID", "==", style));CommentedFeb 26, 2016 at 15:17
    • The result of splitis an Array. You can't split an Array, you can split a String. I can't say much on your usage of the splitted String style, but it seems wrong to use an Array as selector within a query. You can use elements from an Array though: s[element.position], e.g. s[0] returns the first element of array s.
      – KooiInc
      CommentedFeb 26, 2016 at 15:35

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.