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

scm0smlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
Use this.
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.replace("**" + 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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scm0smlAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.