Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post

    Question split sentance in to array

    Hey,

    I have a string which is like the following

    Dear {firstname},

    Recently you.....
    I read it in to an array and split up the paragraph based on " " (a space). The problem is, the above example has no space... so the array looks like

    Code:
    array[0] = "Dear";
    array[1] = "{firstname},Recently";
    array[2] = "you";
    is there a way I could split the string based on commas, full stops or any other way? what's best?

  • #2
    New Coder
    Join Date
    Mar 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't have the exact code to use but i would first subsitute linebreaks for spaces then split into an array. Character escapes that represent new lines are '\r' '\n'. but i'm not sure they are applicable in this situation.

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    try something like this:
    Code:
    test.split(/\s/g)
    Last edited by liorean; 03-18-2004 at 10:08 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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