By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,017 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,017 IT Pros & Developers. It's quick & easy.

How Do I Wrap a Variable in Quotes

P: 4
I'm working with a program to get directories and file types. If I could just get around this problem I'd be done. What I need to do is wrap a [variable] string in quotes before writing it to a text file. I am still pretty new to programming and I've been googling for about the past fourty-five minutes.

Here is the section of code that is giving me trouble.
Expand|Select|Wrap|Line Numbers
  1. Do While Not SR3.Peek = -1
  2.      SW3.WriteLine("compact /c /i " & SR3.ReadLine.Trim)
  3. Loop
What it's doing here is reading a file name from a separate text file and writing it to another text file so it can start compact.exe to compress the certain file. The reason I need to figure out how to wrap what's being written in quotes is because spaces in the file path mess things up.

To aid myself in making sense, here is an example of what is currently being written to the text file:
Expand|Select|Wrap|Line Numbers
  1. compact /c /i C:\ATI\Desktop.ini
Here is what I want:
Expand|Select|Wrap|Line Numbers
  1. compact /c /i "C:\ATI\Desktop.ini"
I've learned some good tricks by reading these forums, but this is my first time posting. I appreciate any help yo uguys could give!
Jun 9 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 5K+
P: 8,434
Just concatenate Chr(34) in there - that's the double-quote character.

I think there's also a built-in constant named something like vbQuote or vbQuotes which contains the quote character, but don't remember for sure.
Jun 11 '07 #2

LacrosseB0ss
100+
P: 113
Just throwing this out there, I don't know for sure, but if spaces are causing a problem, can you not replace those in the path? Use Replace(" ", "%20") is how I would go about it.

But, as previously mentioned, I haven't tried this. I'm going based on previous knowledge.

EDIT:
If Killer gives you a respose though, it's probably better than mine. I trust Killer's judgement. Try that first! ;)
Jun 11 '07 #3

P: 8
The first reply, incorporated in your code would look like

Expand|Select|Wrap|Line Numbers
  1. Do While Not SR3.Peek = -1
  2.      SW3.WriteLine("compact /c /i " & chr$(34) & SR3.ReadLine.Trim & chr$(34))
  3. Loop
Jun 11 '07 #4

P: 4
It works flawlessly now!

Expand|Select|Wrap|Line Numbers
  1. Do While Not SR3.Peek = -1
  2.      SW3.WriteLine("compact /c /i " & Chr(34) & SR3.ReadLine.Trim & Chr(34))
  3. Loop
Many thanks to you Killer42!
Jun 12 '07 #5

Expert 5K+
P: 8,434
It works flawlessly now!
...
Many thanks to you Killer42!
Glad we could help! :)

But it was a team effort, not just me.
Jun 12 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.