inserting single quotes inside a smallTalk string 
Author Message
 inserting single quotes inside a smallTalk string

I want to insert sigle quotes inside a Smalltalk string.

Following expresston:
string := 'select * from ''table'' where field1 = (a at:1).

 evaluates to the output string:
'select * from 'table' where filed1 = name'

I want the output string like this:
'select * from 'table' where filed1 = 'name''.



Tue, 20 Jul 2004 14:47:44 GMT  
 inserting single quotes inside a smallTalk string
Bijunath,

in VAST, I'd use

string := 'select * from ''table'' where field1 = ', (a at:1)
printString.

If that doesn't help further, simply add the quotes by hand, just like
you do it with the table name, like this:

string := 'select * from ''table'' where field1 = ''', (a at:1) ,''''.

Don't trust the inspector with such strings, because it may add
additional quotes in the right pane. Better try a 'Trancript show:
string' to look at the results.

HTH

Joachim

Bijunath schrieb:

Quote:

> I want to insert sigle quotes inside a smallTalk string.

> Following expresston:
> string := 'select * from ''table'' where field1 = (a at:1).

>  evaluates to the output string:
> 'select * from 'table' where filed1 = name'

> I want the output string like this:
> 'select * from 'table' where filed1 = 'name''.

--
----------------------------------------------------------------------

H?slenweg 28                            http://www.objektfabrik.de
D-71642 Ludwigsburg
Telefon: +49 7141 56 10 86 0            Fax: +49 7141 56 10 86 1


Tue, 20 Jul 2004 15:24:06 GMT  
 inserting single quotes inside a smallTalk string

        anArray := Array with: 'name'.
        aStream := WriteStream on: (String new: 50).
        aStream nextPutAll: 'select * from '.
        aStream nextPutAll: 'table' printString.
        aStream nextPutAll: ' where field1 = '.
        aStream nextPutAll: (anArray at: 1) printString.
        Transcript show: aStream contents;cr

I like to break the string down and use printString to acheive the
nested quotes.  It is easier to read IMO.
Don Stacy
Enron

or you can
string := 'select * from ''table'' where field1 = ' (a at:1)
printString.


Quote:

>I want to insert sigle quotes inside a smallTalk string.

>Following expresston:
>string := 'select * from ''table'' where field1 = (a at:1).

> evaluates to the output string:
>'select * from 'table' where filed1 = name'

>I want the output string like this:
>'select * from 'table' where filed1 = 'name''.



Tue, 20 Jul 2004 18:31:13 GMT  
 inserting single quotes inside a smallTalk string


Quote:
>I want to insert sigle quotes inside a smallTalk string.

>Following expresston:
>string := 'select * from ''table'' where field1 = (a at:1).

> evaluates to the output string:
>'select * from 'table' where filed1 = name'

I don't think the expression you give evaluates at all. It appears to me
to have a syntax error.

Quote:

>I want the output string like this:
>'select * from 'table' where filed1 = 'name''.

See if you can figure out how to do it with the String method #, which
means concatenation.

Ronald E Jeffries
http://www.XProgramming.com
http://www.objectmentor.com
I'm giving the best advice I have. You get to decide whether it's true for you.



Tue, 20 Jul 2004 18:51:53 GMT  
 inserting single quotes inside a smallTalk string

Quote:

> I want to insert sigle quotes inside a smallTalk string.

> Following expresston:
> string := 'select * from ''table'' where field1 = (a at:1).

>  evaluates to the output string:
> 'select * from 'table' where filed1 = name'

> I want the output string like this:
> 'select * from 'table' where filed1 = 'name''.

In VW, I think it'd be easy to use:

    'select * from ''<1s>'' where field1 = ''<2s>''' expandMacrosWith: 'table'
with: 'name'

--
.tom



Tue, 20 Jul 2004 23:22:01 GMT  
 inserting single quotes inside a smallTalk string
if (a at:1) always evaluates to a string, you can add a method to the
String class, such as:  asQuotedString.  You can implement that to
accomplish the task, use it over and over again, then, if you discover a
more efficient way to do the task, the only change you need make is to
the asQuotedString method.   The beauty of Smalltalk!
Quote:

> I want to insert sigle quotes inside a smallTalk string.

> Following expresston:
> string := 'select * from ''table'' where field1 = (a at:1).

>  evaluates to the output string:
> 'select * from 'table' where filed1 = name'

> I want the output string like this:
> 'select * from 'table' where filed1 = 'name''.



Wed, 21 Jul 2004 01:28:46 GMT  
 inserting single quotes inside a smallTalk string

Bijunath,

    objects respond to printOn: by printing some representation of
themselves upon a stream, where the default implementation is to print
"a ClassName".  Objects respond to storeOn: by printing a Smalltalk
expression upon a stream that when evaluated reconstructs the receiver.
Streams provide print: and store: as convenient ways of sending printOn:
or storeOn: to their arguments.  So use the following:

string := String new writeStream
                nextPutAll: 'select * from ';
                store: tableName;
                nextPutAll: ' where field1 = ';
                store: fieldName;
                contents

where tableName and fieldName are the strings 'table' and 'name'

HTH

Quote:

> I want to insert sigle quotes inside a smallTalk string.

> Following expresston:
> string := 'select * from ''table'' where field1 = (a at:1).

>  evaluates to the output string:
> 'select * from 'table' where filed1 = name'

> I want the output string like this:
> 'select * from 'table' where filed1 = 'name''.

--
_______________,,,^..^,,,____________________________
Eliot Miranda              Smalltalk - Scene not herd


Wed, 21 Jul 2004 06:58:55 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Making strings with single/double quotes safe for MySQL Insert/Update

2. Putting single quotes inside Prolog strings

3. single-quoted string conversion to triple-quoted string

4. How to insert single quotes into a RealDatabase

5. parsing lines with quoted strings as single fields

6. using gsub on a string containing single quotes

7. Repost:Single quotes in string

8. Single quotes in string

9. replace single quote to double quote with an example

10. strings embedded inside strings

11. Searching for a string inside a string

12. MySQLdb and strings with quotes / long strings

 

 
Powered by phpBB® Forum Software