Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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
Reply With Quote
  #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




Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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.

Reply With Quote
  #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
Reply With Quote
  #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.

Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:51 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.