Link to home
Start Free TrialLog in
Avatar of scm0sml
scm0sml

asked on

removing a substring froma string.

I have the following function.

The section I am interested in is:
strCabinIDs = strCabinIDs - ("**" & cabinid);

I know this isnt correct. What I'm trying to do is remove  the cabinid that is passed in from the string strcabinids.

If there is a ** preceding the id then i need to remove that as well.

Any ideas?
var strCabinIDs
        strCabinIDs = "";
        function CheckCabinQuota(cabinCheckbox,cabinid)
        {         
            alert(strCabinIDs);   
            if(cabinCheckbox.checked == false)//if the user has deselected a cabin
            {
                form1.CurrentCabinCount.value = parseInt(form1.CurrentCabinCount.value) - 1;
                strCabinIDs = strCabinIDs - ("**" & cabinid);// the ** is added to give us something distinctive to split the string on when returning id's
            }
            else//else they are trying to selelct another cabin
            {
                if (form1.AllowedCabinCount.value > form1.CurrentCabinCount.value)//if they have not selected all required cabins 
                {                                                                     
                    form1.CurrentCabinCount.value = parseInt(form1.CurrentCabinCount.value) + 1;
                    strCabinIDs = strCabinIDs + cabinid + "**";// the ** is added to agive us something distinctive to split the string on when returning id's                    
                }
                else
                {
                    alert("You have selected more cabins than required. You must de-select one of your previous choice's before being able to select another.");                    
                    cabinCheckbox.checked = false; //and de-select the choice they have just made.
                } 
            }
            alert(strCabinIDs);                                          
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of scm0sml
scm0sml

ASKER

due to my first id not being peceeded by a ** i changed the ordering to:
strCabinIDs = strCabinIDs.replace(cabinid + "**" , "") so that i remove the id with the following ** as this will always work, even for the first id in the string.