double quotes

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dantomlin
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 43
Joined: Tue Feb 26, 2008 4:07 pm

double quotes

Post by dantomlin » Fri May 10, 2013 9:31 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10057
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: double quotes

Post by FourthWorld » Fri May 10, 2013 9:44 pm

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: double quotes

Post by shaosean » Fri May 10, 2013 10:17 pm

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 addQuotes

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: double quotes

Post by dunbarx » Fri May 10, 2013 11:11 pm

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

andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 184
Joined: Wed Apr 10, 2013 5:09 pm

Re: double quotes

Post by andrewferguson » Sat May 25, 2013 1:53 pm

This code might be what you are wanting.

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 repeat
Andrew

dantomlin
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 43
Joined: Tue Feb 26, 2008 4:07 pm

Re: double quotes

Post by dantomlin » Tue May 28, 2013 5:43 pm

thanks.. I will give it a try.

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: double quotes

Post by mrcoollion » Tue Oct 06, 2015 7:43 pm

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.

Code: Select all

on mouseUp
   put "This is @Item01@  and this is @Item02@"  into theString 
   replace "@" with Quote in theString
   answer theString
end mouseUp
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
Last edited by mrcoollion on Tue Oct 27, 2015 9:35 am, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: double quotes

Post by dunbarx » Tue Oct 06, 2015 8:20 pm

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:

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 addquotes
The function "addQuotes" can be placed in the hierarchy, and you can then use it wherever you please.

Craig

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: double quotes

Post by Simon » Wed Oct 07, 2015 4:57 am

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.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply