SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Text to array

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Text to array

    How would I go about separating each line of a textbox into an array? Here's of example of the kind of text I want to separate.

    text, <b>text</b>, <i>text</i>, text, <br>
    text, <b>text</b>, <i>text</i>, text, <br>
    text, <b>text</b>, <i>text</i>, text, <br>

  2. #2
    SitePoint Enthusiast Moridin_8's Avatar
    Join Date
    Apr 2007
    Location
    UK, soon in USA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by unisite View Post
    How would I go about separating each line of a textbox into an array? Here's of example of the kind of text I want to separate.

    text, <b>text</b>, <i>text</i>, text, <br>
    text, <b>text</b>, <i>text</i>, text, <br>
    text, <b>text</b>, <i>text</i>, text, <br>
    Try something like this maybe?

    Code:
    var thing = document.getElementById("textAreaId").value.split("\n");
    		
    for(str in thing)
    	alert(thing[str]);
    Matt "Moridin8" Warren
    ======================================
    Website: www.csharp-architect.com
    ....IRC: Usually freenode... '##csharp'

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are talking about a string of text, split it on newlines-

    var linearray=stringvalue.split(/\n/);


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •