Results 1 to 5 of 5

Thread: Replace str which has comma with spaces, asp

  1. #1
    Join Date
    Jan 2008
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Replace str which has comma with spaces, asp

    hi everybody..i need some help.
    let say i have one string
    "today, i eat, a, bread"

    how can i count where is the comma and then i need to replace them with spaces?
    is it just use Replace(str,","," ")?

    plz help me..thanx

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Below mentioned is a piece of client-side script in VBScript (Works only in IE) in which your requirement has been demonstrated. Embed the code in your <head> section and load the page in browser.

    Code:
    <script type="text/vbscript">
    	dim txt
    	txt="This,is,a,beautiful,day,!"
    	document.write(txt &"<br/>")
    	str = Replace(txt,","," ")
    	document.write(str)
    </script>
    The above code will replace all the occurrences of comma with space.

    Syntax of Replce

    Replace(string,find,replacewith[,start[,count[,compare]]])

  3. #3
    Join Date
    Jan 2008
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Remember one thing here in html 2 white spaces means 1 even 100 spaces means one if you want to use commas for 100 blank space use this


    StrLine = "Hello,,,,,,,bro,how,,you doing,"
    StrLine2 = Replace (strLine, ",", "&nbsp;",1,-1,1)

    Response.Write StrLine2


    &nbsp; had one problem if you get 100 commas and it changes it to &nbsp; it can kill your page layout the width would be sooooooooo long in that case use Split Function of VB

    Thanks

  4. #4
    Join Date
    Feb 2008
    Location
    Buenos Aires, Argentina
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Red face Try this...

    The Replace function you should use is:

    Code:
    Replace(str, ",", " ", 1)
    That will replace each instance of the comma with an space. Regards!

  5. #5
    Join Date
    Jan 2008
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thank you..problem solve..thanx alot

Bookmarks

Posting Permissions

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