473,396 Members | 2,061 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.

Simple question about double quotes

7
Hello,

I want to add quotes to the front and of strings. That is, I want to turn a list of strings like

Strawberry
Chocolate
Vanilla

into the following list:

"Strawberry"
"Chocolate"
"Vanilla"

I have noticed that a command like
string.replace(x,x[0],"\"\""+x[0])
will put two double quotes in front of a string, but I just want one double quote in front (and one in back).

How do I do this?
Aug 3 '07 #1
2 1982
ghostdog74
511 Expert 256MB
Hello,

I want to add quotes to the front and of strings. That is, I want to turn a list of strings like

Strawberry
Chocolate
Vanilla

into the following list:

"Strawberry"
"Chocolate"
"Vanilla"

I have noticed that a command like
string.replace(x,x[0],"\"\""+x[0])
will put two double quotes in front of a string, but I just want one double quote in front (and one in back).

How do I do this?
there are many ways, one of which is:
Expand|Select|Wrap|Line Numbers
  1. >>> s="strawberry"
  2. >>> s="%s%s%s" % ('"',s,'"')
  3. >>> print s
  4. "strawberry"
  5. >>>
  6.  
  7.  
Aug 3 '07 #2
bartonc
6,596 Expert 4TB
Hello,

I want to add quotes to the front and of strings. That is, I want to turn a list of strings like

Strawberry
Chocolate
Vanilla

into the following list:

"Strawberry"
"Chocolate"
"Vanilla"

I have noticed that a command like
string.replace(x,x[0],"\"\""+x[0])
will put two double quotes in front of a string, but I just want one double quote in front (and one in back).

How do I do this?
You can use double quotes inside single quotes, and vice versa, as if they are any other character:
Expand|Select|Wrap|Line Numbers
  1. >>> print '"strawberry"'
  2. "strawberry"
  3. >>> print "'strawberry'"
  4. 'strawberry'
  5. >>>
  6. >>> fruit = 'strawberry'
  7. >>> print "'%s'" %fruit
  8. 'strawberry'
  9. >>> print '"%s"' %fruit
  10. "strawberry"
  11. >>>
Aug 3 '07 #3

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

Similar topics

11
by: Jakanapes | last post by:
Hi all, I'm looking for a way to scan a block of text and replace all the double quotes (") with single quotes ('). I'm using PHP to pull text out of a mySQL table and then feed the text into...
2
by: Gene Ellis | last post by:
Put simple I would like to have this line in my XSL template: document.writeln("<a href='http://www.mydomain.com/user/login.php' class='login'>") My XML parser seems to be breaking on the...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
4
by: (PeteCresswell) | last post by:
Is his just a flat-out "No-No" or is there some workaround when it comes time for SQL searches and DAO.FindFirsts against fields containing same? I can see maybe wrapping the value searched for...
12
by: Brett Hofer | last post by:
I must be missing something - Im a veteran C++ programmer now working with C# overall I like the language but find many weird changes... Anyway Im writing code behind an aspx. In this one C#...
5
by: Tim::.. | last post by:
Can someone tell me how I convert this simple SQL statement so I can use it in ASP.NET??? I have an issue with the quotation marks and wondered if there is a simple rule for converting the sql...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
15
by: Jofio | last post by:
I have 40 or jpeg files which I want them displayed in a frame called "main" upon clicking thumbnails of the same pics in a "leftMenu" frame. The thumbnail jpeg files are called thumb1, thumb2,...
7
by: Steven W. Orr | last post by:
Python has a number of "quoting" 'options' to help """with times when""" one way may be more convenient than another. In the world of shell scripting, I use a technique that I call minimal...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.