473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to double quote a variable string?

6
Hi, I'd like to know how to add double quote to a string variable. For example,
Expand|Select|Wrap|Line Numbers
  1. string filename = @"C:\my file";
  2. arguments = "-i " + filename;
  3.  
So arguments = @"-i C:\my file".

But I want arguments = @"-i "C:\my file"". How to do it with filename only? I tried,
arguments = "-i " + "\"filename\"";
but only get arguments = @"-i "filename"".

Any thought?
Feb 26 '11 #1

✓ answered by Plater

so if you have a file called:
c:\my filename.dat
You need an argument string to be:
-i "c:\my filename.dat" correct?

So for example:
Expand|Select|Wrap|Line Numbers
  1. string SomeFilename=@"c:\my filename.dat";
  2. string arguments=string.Format("-i \"{0}\"",SomeFilename);
  3.  

11 15435
If I'm understanding it right, I think you're very close...

The "filename" variable name needs to be appended to the rest of the string, so you could do something like:
Expand|Select|Wrap|Line Numbers
  1. string filename = @"C:\my file";
  2. arguments = "-i \"" + filename + "\"";
Feb 27 '11 #2
york
6
I tried that, but get
arguments = "-i \"C:\\my file\"".
How to remove 2 extra "\" in the string?
Feb 27 '11 #3
I think you may be getting confused with the use of the verbatim literal (@ symbol). If you're using this before the string, then all escape characters (like the extra '\') will be included.
Feb 27 '11 #4
york
6
But I did not use verbatim for arguments ( there is no @ before it). How to get rid of \ is a big problem.
Feb 27 '11 #5
That does seem odd... Could you specify what type of variable "arguments" is?

In the code segment I gave you earlier, I tried it with arguments as a string and then displayed it in a MessageBox. It was formatted without the '\' characters.

Expand|Select|Wrap|Line Numbers
  1. string filename = @"C:\my file";
  2. string arguments = "-i \"" + filename + "\"";
  3. MessageBox.Show(arguments);
Here's an MSDN link that may help out as well:
http://msdn.microsoft.com/en-us/libr...90(VS.71).aspx
Feb 27 '11 #6
york
6
arguments is string. I also display it using console.write and the result is correct.

What I really want is to create ffmpeg command that can accept filename with space in it. The command is like
ffmpeg -i "C:\my file"
The reason to have double quote on filename is that ffmpeg only accept file name without space, and so
ffmpeg -i C:\my file
is considered as ffmpeg -i C:\my
However, the filename must be a variable. So I use
Expand|Select|Wrap|Line Numbers
  1. string arguments = "ffmpeg -i " + "\"" + filename + "\"";
For any filename, it will be
ffmpeg -i "filename" (filename is a variable)
But in debugger, arguments is displayed as
"ffmpeg -i \"C:\\my file\""
And ffmpeg can not execute right. However when using
Expand|Select|Wrap|Line Numbers
  1. console.write(arguments);
It display correctly as ffmpeg -i "C:\my file".
So it is weired.
Feb 28 '11 #7
Rabbit
12,516 Expert Mod 8TB
Have you tried using two double quotes to escape it instead of a backslash?
Feb 28 '11 #8
york
6
yes, I tried with 2 double quotes without \, but it gives
arguments = "ffmpeg -i C:\my file"
not what I need.
Feb 28 '11 #9
Plater
7,872 Expert 4TB
so if you have a file called:
c:\my filename.dat
You need an argument string to be:
-i "c:\my filename.dat" correct?

So for example:
Expand|Select|Wrap|Line Numbers
  1. string SomeFilename=@"c:\my filename.dat";
  2. string arguments=string.Format("-i \"{0}\"",SomeFilename);
  3.  
Feb 28 '11 #10
york
6
Thanks a lot, Plater, it is working finally.
Feb 28 '11 #11
This can be tried for the same issue.
string filename = @"c:\my file";
string output ="@" + "\"" + "-i\"" + filename + "\""+"\"";
Dec 4 '12 #12

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

Similar topics

4
by: Alden Streeter | last post by:
Here is the HTML that is being output by my asp page: <a href='Files/category/computers/bigimages/computers-sub-monitors.jpg' target='_blank' onMouseOver="window.status='Click for a larger image...
2
by: Diarmaid McGleenan | last post by:
Hi all. This isn't quite the same single/double-quote problem we see posted a multitude of times in this ng. Read on... I have a js function called ShowActiveLink which accepts a string...
8
by: Ahmad A. Rahman | last post by:
Hi all, I have a problem constructing a regular expression using .net. I have a string, separated with comma, and I want to group the string together but, I failed to group a numeric character...
3
by: Özden Irmak | last post by:
Hi, I've to add ( " ) double quote character to a string which I later save the string into a file? How can I add this character to a string in C#? 3 times double quote doesn't seem to...
4
by: fred | last post by:
Hi, is there a way to put " (double quote) into a verbatin string? thank you
2
by: Edward | last post by:
My function to populate fields on a form from a collection: Private Sub cbfSetUpAddresses(ByVal pcolAddress As Collection) Line 1 Me.txtAddress1.Text = pcolAddress(1).ToString Line 2 ...
4
by: Kevin Thomas | last post by:
Hi there, If I have a string var, strFoo that contains double-quotes such that it looks like this: I "love" VB What do I pass into the "replace" method to replace the double-quotes with...
9
by: Huy | last post by:
I've been unable to find information clarifying this but. What is the difference between 'somestring' and "somestring"? When I use type() it still reports as string. If there is a difference...
1
by: U Aye Thein | last post by:
I found in internet how to solve single quotation mark in string and how to solve double quotation mark in string but my string may be contained single quote or double quote. How to write an...
4
by: zacks | last post by:
I need to check the current value of a string value to see if it either starts with or ends with a double quote character, as in "123" (where the quotes are actual contens of the string). I thought...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.