double quotes
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
double quotes
I need to add double quotes to each item in a variable.  I have 183 fields in a variable and I need to create a file with each field enclosed in quotes in order to import into another system.
I have been trying a repeat loop but having trouble getting the quotes around each item in the variable...
Any suggestions would be greatly appreciated....
Thanks, Dan
			
			
									
									
						I have been trying a repeat loop but having trouble getting the quotes around each item in the variable...
Any suggestions would be greatly appreciated....
Thanks, Dan
- 
				FourthWorld
- VIP Livecode Opensource Backer 
- Posts: 10065
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: double quotes
Post the code you have and we can revise it.
			
			
									
									Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
						LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: double quotes
Code: Select all
function addQuotes pDataIn
  local tDataOut
  repeat for each line tLine in pDataIn
    put QUOTE & tLine & QUOTE & LF after tDataOut
  end repeat
  if (char -1 of tDataOut = LF) then
    delete char -1 of tDataOut
  end if
  return tDataOut
end addQuotesRe: double quotes
What Shaosean said.
What you may have stumbled over is that since quotes are used intimately in the language, to define literals, for example, the engine will not simply add them just because you wrote them. For example, if you write"
put "foo" into myVariable -- you will find foo, not "foo"
What you want is to use the quote constant (see the dictionary):
put quote & "foo" & quote into myVariable --now you will find "foo"
So it is important to see that with such a highly integrated native element as a double quote, which is used to help the engine parse its code, the constant "quote" (no joke intended) is provided to explicitly add a double quote to a string. There are other constants that fall into the same category, though probably not so egregiously.
Craig Newman
			
			
									
									
						What you may have stumbled over is that since quotes are used intimately in the language, to define literals, for example, the engine will not simply add them just because you wrote them. For example, if you write"
put "foo" into myVariable -- you will find foo, not "foo"
What you want is to use the quote constant (see the dictionary):
put quote & "foo" & quote into myVariable --now you will find "foo"
So it is important to see that with such a highly integrated native element as a double quote, which is used to help the engine parse its code, the constant "quote" (no joke intended) is provided to explicitly add a double quote to a string. There are other constants that fall into the same category, though probably not so egregiously.
Craig Newman
- 
				andrewferguson
- VIP Livecode Opensource Backer 
- Posts: 184
- Joined: Wed Apr 10, 2013 5:09 pm
Re: double quotes
This code might be what you are wanting.
Andrew
			
			
									
									
						Code: Select all
   --This Code puts quotes around all the words from the variable input, and places the end result into the variable output
   global input, output
   put empty into output
   put 1 into counter
   repeat for the number of words of input
      put quote & word counter of input & quote & space after output
      add 1 to counter
   end repeatRe: double quotes
thanks..   I will give it a try.
			
			
									
									
						- 
				mrcoollion
- Posts: 740
- Joined: Thu Sep 11, 2014 1:49 pm
Re: double quotes
Because i got tired of adding double quotes to each item in a variable and because sometimes it gives me trouble I use the following very simple method that only needs one additional script-line.
Place the following in a button script and you will see how easy it is.
Hope this makes it somewhat easier for some of us.
And of-course you can replace the @ for anything you like as long as it is not a part of the original string ( eg #q# or anything else).
Kind regards,
Paul
			
			
													Place the following in a button script and you will see how easy it is.
Code: Select all
on mouseUp
   put "This is @Item01@  and this is @Item02@"  into theString 
   replace "@" with Quote in theString
   answer theString
end mouseUp
And of-course you can replace the @ for anything you like as long as it is not a part of the original string ( eg #q# or anything else).
Kind regards,
Paul
					Last edited by mrcoollion on Tue Oct 27, 2015 9:35 am, edited 1 time in total.
									
			
									
						Re: double quotes
Hi.
Nothing like building your own toolbox of goodies. One sometimes spends more effort on these than on the project itself. But think about this. You need a button and a field. In the button script:
The function "addQuotes" can be placed in the hierarchy, and you can then use it wherever you please.
Craig
			
			
									
									
						Nothing like building your own toolbox of goodies. One sometimes spends more effort on these than on the project itself. But think about this. You need a button and a field. In the button script:
Code: Select all
on mouseUp
   put "ABC" into temp
   answer temp --just the literal
   put addQuotes(temp) into fld 1 --quotes added to temp
end mouseUp
function addquotes var
   return quote & var & quote
end addquotesCraig
Re: double quotes
Do I get to post this again?
http://forums.livecode.com/viewtopic.ph ... 73#p100173
Ohh too late to stop me...
Klaus has a different method as well.
Simon
ooops; same problem different situation.
			
			
									
									http://forums.livecode.com/viewtopic.ph ... 73#p100173
Ohh too late to stop me...

Klaus has a different method as well.
Simon
ooops; same problem different situation.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
						