Stripping Characters out of Strings ?

This is a discussion on "Stripping Characters out of Strings ?" within the JavaScript Forum section. This forum, and the thread "Stripping Characters out of Strings ? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 22nd, 2006, 14:37
New Member
Join Date: Aug 2006
Location: UK
Age: 40
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Stripping Characters out of Strings ?

Hi, i am new to JavaScript so please accept my apologies if this is a simple question.

I need to write a Function that will take a String (entered through a TextBox on an .asp Page by a User), and strip a range of characters (e.g. "," "/" "'" "|") out of it, and replace them with nothing.

For example(s) :-

02/09/1967 should become 02091967
a,b should become ab

Any help appreciated.

Thanks,

Mark.

mark.davies@npower.com
Reply With Quote

  #2 (permalink)  
Old Aug 22nd, 2006, 15:13
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Stripping Characters out of Strings ?

Hi!

This code should serve you need pretty well.....

just pass it the string to look in, what to look for, and what to replace it with.

HTML: Select all
//**************************************
//     
// Name: A Replace String Example THAT W
//     ORKS
// Description:All of the replace string
//     code I've found on planetsourcecode DOES
//     NOT WORK! I took one of the broken examp
//     les and fixed it. This is no joke. It do
//     es work.
// By: Mark Anthony Entingh
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=4095&lngWId=2//for details.//**************************************
//     


    function xreplace(checkMe,toberep,repwith){
        temp = checkMe;
        a = 0;


            for(i = 0; i < checkMe.length; i++){
                a = temp.indexOf(toberep);
        temp = temp.substring(0 , a) + repwith + temp.substring((a + toberep.length));


            if (a == -1){
                break;
        }

            }
            return temp;
    }
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Reply With Quote
  #3 (permalink)  
Old Aug 23rd, 2006, 07:13
New Member
Join Date: Aug 2006
Location: UK
Age: 40
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Stripping Characters out of Strings ?

Thanks very much Rob, i'll give it a go.
Reply With Quote
  #4 (permalink)  
Old Aug 23rd, 2006, 20:35
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: Stripping Characters out of Strings ?

Whether you are doing this client side with JavaScript or server side with something like PHP, you might want to look at regular expressions.

They can do this and much, much more besides. The effort of getting to know how to use them will be well spent.
Reply With Quote
Reply

Tags
stripping, characters, strings

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read First 3 characters and last 4 characters of string JustinStudios PHP Forum 2 Apr 4th, 2008 00:01
cutting strings alexgeek PHP Forum 5 Aug 29th, 2007 17:12
Javascript Strings Help Sabin_33 JavaScript Forum 2 Dec 21st, 2006 09:54
Confused with strings... ktsirig Other Programming Languages 1 Jan 11th, 2006 18:02
Quotes in strings jakyra Classic ASP 5 Sep 9th, 2003 15:10


All times are GMT. The time now is 05:40.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43