Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 4th, 2005, 04:14 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default Replace

I have four functions:

Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Ampersand character with 'AND'
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_ampersand(ByVal strValue As String) As String
fix_ampersand = Replace(strValue, "&", "AND")
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Apostrophe character with "" (empty)
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_apostrophe(ByVal strValue As String) As String
fix_apostrophe = Replace(strValue, "'", "")
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Colon character with "" (empty)
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_colon(ByVal strValue As String) As String
fix_colon = Replace(strValue, ":", "")
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Comma character with "" (empty)
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_comma(ByVal strValue As String) As String
fix_comma = Replace(strValue, ",", "")
End Function
how can i add them all into one function and just replace each character i.e. comma, apostrophe, etc with "" (blank).


is there a 'strip' command?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
  #2 (permalink)  
Old May 4th, 2005, 04:36 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Put the three replace statements inside one function.This will replace with ""
Public Function fix_characters(ByVal strValue As String) As String
  fix_apostrophe = Replace(strValue, "'", "")
  fix_colon = Replace(strValue, ":", "")
  fix_comma = Replace(strValue, ",", "")
End Function




  #3 (permalink)  
Old May 4th, 2005, 04:52 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

with that code i get a Compile Error:

Function call on left side of assignment must return Variant or Object

heres my code:

Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Ampersand character with 'AND'
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_ampersand(ByVal strValue As String) As String
fix_ampersand = Replace(strValue, "&", "AND")
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Apostrophe character with 'AND'
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_apostrophe(ByVal strValue As String) As String
fix_apostrophe = Replace(strValue, "'", "")
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Colon character with ''
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_colon(ByVal strValue As String) As String
fix_colon = Replace(strValue, ":", "")
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace Comma character with ''
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_comma(ByVal strValue As String) As String
fix_comma = Replace(strValue, ",", "")
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace all characters with ""
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_characters(ByVal strValue As String) As String
  fix_apostrophe = Replace(strValue, "'", "")
  fix_colon = Replace(strValue, ":", "")
  fix_comma = Replace(strValue, ",", "")
End Function
and where i call it:

Code:
fix_characters(Trim(the_Content))
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
  #4 (permalink)  
Old May 4th, 2005, 04:55 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

change to:

Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace all characters with ""
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function fix_characters(ByVal strValue As String) As String
  fix_characters = Replace(strValue, "'", "")
  fix_characters = Replace(strValue, ":", "")
  fix_characters = Replace(strValue, ",", "")
End Function
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
  #5 (permalink)  
Old May 4th, 2005, 05:07 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Cool.

  #6 (permalink)  
Old May 4th, 2005, 06:14 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

This should be simple, but it's got me: how do you use 'Replace' to
replace double quotes? This won't work:

    Replace(strString,""","'")

to replace the double quotes with singles, for instance. I just know I'm
missing something obvious here.

Thanks.


www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
  #7 (permalink)  
Old May 4th, 2005, 07:43 AM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Replace(strSting,CHR(34),"'")
Say Hi to Paul & David for me.

  #8 (permalink)  
Old May 4th, 2005, 07:55 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you say "this won't work", you might want to be a little bit more specific

In fact, if you're using the VB editor, your example
Code:
Replace(strString,""","'")
won't even compile and the editor will highlight it straight away with a warning dialog

Basically you need to escape the double-quote character [Chr$(34)] as it's a special character for the VB compiler

You need to type
Code:
Replace(strString,"""","'")
ie. 4 instances of the double-quote character
  #9 (permalink)  
Old May 17th, 2005, 09:35 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Is this correct VB code:

Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''
' Replace all problematic characters with ""
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fix_characters(ByVal strValue As String) As String
    fix_characters = Replace(strValue, "'", "")
    fix_characters = Replace(strValue, ":", "")
    fix_characters = Replace(strValue, ",", "")
    fix_characters = Replace(strValue, """", "")
End Function
I'm not sure if its working....

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
  #10 (permalink)  
Old May 17th, 2005, 09:45 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm you have to replace that chars with nothing or with "" (double quote)...

also.. you will only replace the """" b/c you are using always the same destination...

do something like this¨

Code:
Public Function fix_characters(ByVal strValue As String) As String
[TAB]dim sStrTemp as string
    sStrTemp = Replace(strValue, "'", "")
    sStrTemp = Replace(sStrTemp , ":", "")
    sStrTemp = Replace(sStrTemp , ",", "")
    sStrTemp = Replace(sStrTemp , """", "")
fix_characters = sStrTemp 
End Function




HTH

Gonzalo




Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace In c# jayanth_nadig SQL Language 2 July 3rd, 2006 03:25 AM
replace ' and " with \' and \" Brian Campbell XSLT 4 May 24th, 2006 10:49 AM
replace "." with "/" thelos Excel VBA 1 September 14th, 2005 10:47 AM
replace() Missy_K Javascript 1 January 16th, 2004 11:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.