|
-
Dec 9th, 2005, 03:07 AM
#1
Thread Starter
Addicted Member
[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 ^_^
-
Dec 9th, 2005, 03:17 AM
#2
Re: Escaping " marks
How do you read it from the file?
Show us some code.
-
Dec 9th, 2005, 03:49 AM
#3
Thread Starter
Addicted Member
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 ^_^
-
Dec 9th, 2005, 07:31 AM
#4
Re: Escaping " marks
You can always just remove them altogether.
VB Code:
Text1.Text = Replace(Text1.Text, Chr(34), Space(0))
-
Dec 9th, 2005, 07:56 AM
#5
Re: Escaping " marks
 Originally Posted by Hack
You can always just remove them altogether.
VB Code:
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:
'Before storing it in a file:
TempString = Replace(Text1.Text, Chr(34), "<TempChar>")
'After retrieving it from the file
Text1.Text = Replace(TempString, "<TempChar>", Chr(34))
I think this will fix this issue.
-
Dec 9th, 2005, 08:25 AM
#6
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:
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
NewText = Input(LOF(FF), #FF)
close #FF
Text1.text = NewText
Or else something like this:
VB Code:
Dim NewText as string
Dim TotalText 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)
Line Input #FF, NewText
Totaltext = TotalText & Newtext & vbCRLF
wend
close #FF
Text1.text = TotalText
-
Dec 9th, 2005, 01:09 PM
#7
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|