Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cutting out between the words

    is there a function that would remove character beteen two words?
    eg
    suppose i had a "hello this is me how are you doing" and i pass me and you i want the string to be "hello this is me you doing"

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    <script>
    var textstring = "Hello this is me how are you doing";
    var newtextstring = textstring.replace("how are you ","");
    </script>

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no the problem is i don't know what is between me and you so i can only supply those two. some junk characters are being placed in between. i just gave it as example and said i want to pass me and you and get rid of everyting in between that

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    function removeStr(str, start, end){
      var pattern = new RegExp(start + ".*" + end, "gi");
      return str.replace(pattern, start + " " + end);
    }
    
    var s = "Hello this is me how are you doing";
    alert(removeStr(s, "me", "you"));


  •  

    Posting Permissions

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