Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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
 
Old September 21st, 2007, 11:05 AM
Authorized User
 
Join Date: Sep 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Removing Double Quotes from a string

I'm developing a web page using VB.NET that will write a string to a file (txt) based on user input, using the FileOpen/FileClose functions which works fine. User entry type (either textbox or ddl) has not been determined yet, so in the meantime, I've hard coded my strings:
      Dim strFY = "salehistp:fyear"
      Dim strPrd = "salehistp:period"
      Dim strconc As String = strFY + " " + strPrd

The problem I have is that the text file that I write to using the FileOpen/FileClose functions contains the string with double quotation marks which I can't use in my text file:
      "salehistp:fyear salehitsp:period"

I've tried the replace:
      strconc.Replace("""", "")

Also the CleanInput function below passing strconc (CleanInput(strconc)):
     Function CleanInput(ByVal strIn As String) As String
       ' Replace invalid characters with empty strings.
         Return Regex.Replace(strIn, "[^\w\.@-]", "")
     End Function

And I've tried using the following function passing strconc in the same manner:
    Function CheckSQ(ByVal lsInput)
      Dim llPos
      Dim lsOutput

      lsOutput = lsInput

      llPos = 1
      Do While llPos <> 0
         llPos = InStr(llPos, lsOutput, "'", vbTextCompare)

         If llPos <> 0 Then
            lsOutput = Left(lsOutput, llPos - 1) & "`" & Right (lsOutput, Len(lsOutput) - llPos)
         End If
      Loop

      llPos = 1
      Do While llPos <> 0
         llPos = InStr(llPos, lsOutput, """", vbTextCompare)

         If llPos <> 0 Then
            lsOutput = Left(lsOutput, llPos - 1) & "`" & Right(lsOutput, Len(lsOutput) - llPos)
         End If
      Loop

      CheckSQ = lsOutput
   End Function

None of these options have worked for me. My text file still contains data I wrote to it with double quotes. Any ideas on what I'm doing wrong or what can be done differently to remove the double quotation marks?

Your time is greatly appreciated.


 
Old September 21st, 2007, 11:10 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. you are adding the double quotations in other part of your code, since
Code:
      Dim strFY = "salehistp:fyear"
      Dim strPrd = "salehistp:period"
      Dim strconc As String = strFY + " " + strPrd
       will produce the string you need...
how are you storing it into the text file?? maybe there is the problem...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 21st, 2007, 11:25 AM
Authorized User
 
Join Date: Sep 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm trying to strip the string of it's double quotes before i write it to the text file. I assign a label (lblFYPrd) on my page the contents of the string (after trying to strip the quotes) and then us the value of the label to write to the text file. I'm using the following code to write my string to the text file.
  FileOpen(1, "c:\somepath\TESTFILE.txt", OpenMode.Output,
    OpenAccess.Write, OpenShare.Shared)
      Write(1, lblFYPrd.Text)
  FileClose(1)

does this answer your question? Thanks

 
Old September 21st, 2007, 11:39 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Based on the code I've seen so far, your string should not contain any quotes. How are you assigning the value to the label? Can we see that code?

-Peter
 
Old September 21st, 2007, 11:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

found it..

the write function add double quotes around the strings. Read this to have a better understand:
http://msdn2.microsoft.com/en-us/lib...tem.write.aspx

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 21st, 2007, 11:45 AM
Authorized User
 
Join Date: Sep 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

lblFYPrd.Text = strconc.Replace("""", "")

The code from start to finish:
     Dim strFY = "salehistp:fyear"
      Dim strPrd = "salehistp:period"
      Dim strconc As String = strFY + " " + strPrd
      CleanInput(strconc)
      CheckSQ(strconc)

      lblFYPrd.Text = strconc.Replace("""", "")

     FileOpen(1, "c:\somepath\TESTFILE.txt", OpenMode.Output, OpenAccess.Write, OpenShare.Shared)
      Write(1, lblFYPrd.Text)
      FileClose(1)

Hope this helps. Thanks


 
Old September 21st, 2007, 12:34 PM
Authorized User
 
Join Date: Sep 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

excellent read. Thank You. I used the Print instead of the Write and now my string has no double quotes or a comma at the end.

There is still one thing I don't understand. When I debug this page and check the contents of the string after passing it through each function and using the replace, it appears that the quotes are still a part of the string. Are the functions working or it it the print that removes my quotes.

Thanks


 
Old September 21st, 2007, 12:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

where are you checking your string?? maybe is the same problem.. you are seeing quotes b/c you are looking at a string..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old September 21st, 2007, 02:14 PM
Authorized User
 
Join Date: Sep 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm checking the contents of the string via the WATCH when debugging and hovering over the variable (lblFYPrd.Text) with the mouse.

As long as the quotes are removed in the text file :).

Thanks


 
Old September 24th, 2007, 09:03 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think what Gonzalo is saying is that when you look at a string value in the debugger the debugger shows the string inside of quotes simply because it is a string (versus an integer or other non-string type). The quotes are not actually characters within the string itself.



-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
double quotes MyronCope Classic ASP Basics 2 November 21st, 2006 09:31 AM
Removing Double Qoutes from string hexOffender VB.NET 2002/2003 Basics 2 June 26th, 2006 02:44 PM
displaying single quotes and double quotes ren_123 Classic ASP Databases 2 February 22nd, 2006 02:17 PM
Double Quotes langer123 Classic ASP Basics 2 March 16th, 2005 06:22 PM
Double Quotes and Single Quotes Problem phungleon Classic ASP Basics 7 May 27th, 2004 01:44 PM





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