Results 1 to 7 of 7

Thread: [RESOLVED] Escaping " marks

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Resolved [RESOLVED] Escaping " marks

    Hi all,

    Quick question:
    I'm writing a program where the user writes stuff in a text box, and submits them to the server, and then it can download them and output them again, similar to an e-mail/messenger kind of thing. The problem is that if you put " marks in the text box, VB picks that up as the end of string and only outputs so much. For example, the string:

    Code:
    
    regfop8uyh3ulok5hy79
    
    df8oyuvbh53einhu5
    
    e4y5gh
    
    
    
    
    
    erdhbgy45e5uh
    
    
    
    """"""
    
    dgbf08u5
    
    ""
    
    3w09tujew89gtij){*U($
    will only display the value:

    Code:
    
    3w09tujew89gtij){*U($
    It stores the data to the server (via FTP) fine, downloads it fine, the problem is in the reading of the file. So my basic question is: How can you excapt Quote "" marks in text fields so that they show up as part of the string, and aren't used as an operator?


    Thanks ^_^

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Escaping " marks

    How do you read it from the file?
    Show us some code.
    Frans

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Escaping " marks

    Well, it downloads from the server the text file, which is intact when it arrives (i.e. with all of the text in). I'm at college right now so I don't have the EXACT code in front of me, but it's something like:

    Code:
    Dim NewText as string
    Dim FF as integer
    
    FF=freefile()
    
    <code that downloads the file from the server to C:\Message.txt>
    
    Open "C:\Message.txt" for input as #FF
    While not EOF(FF)
       Input #FF, NewText
    wend
    close #FF
    
    Text1.text = NewText
    I just need to know how to escape " marks ^_^

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Escaping " marks

    You can always just remove them altogether.
    VB Code:
    1. Text1.Text = Replace(Text1.Text, Chr(34), Space(0))

  5. #5
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Escaping " marks

    Quote Originally Posted by Hack
    You can always just remove them altogether.
    VB Code:
    1. Text1.Text = Replace(Text1.Text, Chr(34), Space(0))
    Without removing it we can just replace that characters with some other character. When storing the text in a file we can temporarily replace it with some other junk characters and when we retrieve it from the file we can replace the same with double quotes.
    VB Code:
    1. 'Before storing it in a file:
    2. TempString = Replace(Text1.Text, Chr(34), "<TempChar>")
    3. 'After retrieving it from the file
    4. Text1.Text = Replace(TempString, "<TempChar>", Chr(34))
    I think this will fix this issue.
    CS

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Escaping " marks

    I see two errors in your code.

    Error #1
    You use the input function, which will ignore double quotationmarks
    Use another method to read the file, like Line Input or the other Input function that accepts the number of bytes to read as the first parameter.

    Error #2
    In every loop you replace the existing value of Newtext with the newly read value. Either don't use a loop, or read it into a variable first, and append the result to another variable.

    This should work:
    VB Code:
    1. Dim NewText as string
    2. Dim FF as integer
    3.  
    4. FF=freefile()
    5.  
    6. <code that downloads the file from the server to C:\Message.txt>
    7.  
    8. Open "C:\Message.txt" for input as #FF
    9. NewText  = Input(LOF(FF), #FF) 
    10. close #FF
    11.  
    12. Text1.text = NewText

    Or else something like this:
    VB Code:
    1. Dim NewText as string
    2. Dim TotalText as String
    3. Dim FF as integer
    4.  
    5. FF=freefile()
    6.  
    7. <code that downloads the file from the server to C:\Message.txt>
    8.  
    9. Open "C:\Message.txt" for input as #FF
    10. While not EOF(FF)
    11.    Line Input #FF, NewText
    12.    Totaltext = TotalText & Newtext & vbCRLF
    13. wend
    14. close #FF
    15.  
    16. Text1.text = TotalText
    Frans

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Escaping " marks

    Cssriraman - I implemented your method, works perfectly! Thank you very much ^_^

    Also thanks a lot to everyone else who gave advice/suggestions ^_^

Posting Permissions

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



Click Here to Expand Forum to Full Width