Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 21st, 2005, 10:06 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default split()

Hi,

I'm running this function on a string, but sometimes that string doesn't have a " "... how can I test to see if it does or not before running the function.. so I don't get errors...

function trimFat(str)
{
    var temp = new Array();
    temp = str.split(" ");
    return (temp[0]);
}

 
Old October 21st, 2005, 11:34 AM
Registered User
 
Join Date: Jun 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use the str.indexOf function, so it would be:

function trimFat(str)
{
    if(str.indexOf(" "))
    {
        var temp = new Array();
        temp = str.split(" ");
        return (temp[0]);
    }
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
To Split or Not to Split darrenb Access 2 February 8th, 2008 12:28 PM
Split crmpicco VB How-To 6 May 17th, 2005 04:16 AM
split crmpicco Classic ASP Basics 2 February 14th, 2005 08:48 AM
Split database rylemer Access 1 August 30th, 2004 05:33 PM
help using split command chrisangus@btinternet.com Beginning VB 6 2 June 23rd, 2003 12:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.