CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: Split string

  1. #1
    Join Date
    Mar 2006

    Question Split string


    does anyone know how to split a string?

    so far I have the following:

    var string = "Hello my name is - Bob";
    alert( sring.split('-', 2) );
    however, I am not 100% sure if i am doing it correct.

    I am trying to get the bob part of the string only.

    but it displays Hello my name is , bob

    Does anyone know what I am doing wrong?

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002

    Re: Split string

    You're splitting properly. Remember that it returns an array.

    This is very, very basic JavaScript. I suggest you go to W3Schools' JavaScript section and brush up a bit.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2012

    Re: Split string

    Here is the code to split a string in javascript..Hope it will work for you

    string.split(separator, limit)

    An example for your help goes like this :

    <script type="text/javascript">

    var str="How are you doing today?";

    document.write(str.split() + "<br />");
    document.write(str.split(" ") + "<br />");
    document.write(str.split("") + "<br />");
    document.write(str.split(" ",3));


Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)