• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1429
  • Last Modified:

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

0
scm0sml
Asked:
scm0sml
1 Solution
 
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
 
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now