String manipulation 
Author Message
 String manipulation

Hi folks,

Anyone know how I can strip characters out of string before printing it?

The string will be something like "(402)123456787890" and I want to be
able to strip out the open and close brackets.

The red book doesn't seem to have any useful examples of string
manipulation.

Thanks in advance for any help.

Cheers,

Duncan Kinnear.



Fri, 02 May 2003 10:13:49 GMT  
 String manipulation

Quote:

>Hi folks,

>Anyone know how I can strip characters out of string before printing it?

>The string will be something like "(402)123456787890" and I want to be
>able to strip out the open and close brackets.

In this case, you'd copy the characters one at a time from one string
to a new string. Use get and put. When you are finished you will need
to shorten the target string

target_string 0 required_length 1 sub getinterval

will return the string of the correct length.
----------------------------------------

Visit http://www.*-*-*.com/ ,
PSAlter, psalters, tea, and small {*filter*} animals. And stuff.  



Fri, 02 May 2003 03:00:00 GMT  
 String manipulation
Duncan Kinnear a crit dans le message

Quote:
>Anyone know how I can strip characters out of string before printing it?
>The string will be something like "(402)123456787890" and I want to be
>able to strip out the open and close brackets.

Depending on what your situation is and whether you only need to suppress
graphical output, another option maybe to avoid printing parentheses
altogether by defining a font encoding for which parentheses' character
codes 40 and 41 are non-marking characters (like space) and ideally zero
width as well (this second statement may prove impossible to reach in many
cases).
Of course, if the scope of the exercise is to learn string manipulation in
PS, that's a bit off target...
__________________________________
Fran?ois Robert
To mail me : reverse order of all characters in address


Fri, 02 May 2003 03:00:00 GMT  
 String manipulation


Quote:
>Hi folks,

>Anyone know how I can strip characters out of string before printing it?

>The string will be something like "(402)123456787890" and I want to be
>able to strip out the open and close brackets.

>The red book doesn't seem to have any useful examples of string
>manipulation.

>Thanks in advance for any help.

>Cheers,

>Duncan Kinnear.

Hello Duncan

If the string structure is always as shown in your example with the
bracketed digits at the beginning and you only require to print the
characters in the string omitting the inner brackets then the token
operator will do the needful. In the above structure it will return
a true and 2 strings. Pop the boolean and show the strings (or define
them for later use). Not really much string manipulation but maybe
adequate. Rough examples follow

Regards

George

%!
100 100 moveto
((402)123456789070) token pop show show

100 200 moveto
((98765)25680) token pop show show

100 300 moveto
((15)0987654321) token pop show show

showpage

George Spowart                    



Fri, 02 May 2003 03:00:00 GMT  
 String manipulation


Quote:


>>Hi folks,

>>Anyone know how I can strip characters out of string before printing it?

>>The string will be something like "(402)123456787890" and I want to be
>>able to strip out the open and close brackets.

>>The red book doesn't seem to have any useful examples of string
>>manipulation.

>>Thanks in advance for any help.

>>Cheers,

>>Duncan Kinnear.

>Hello Duncan

>If the string structure is always as shown in your example with the
>bracketed digits at the beginning and you only require to print the
>characters in the string omitting the inner brackets then the token
>operator will do the needful. In the above structure it will return
>a true and 2 strings. Pop the boolean and show the strings (or define
>them for later use). Not really much string manipulation but maybe
>adequate. Rough examples follow

>Regards

>George

>%!
>100 100 moveto
>((402)123456789070) token pop show show

>100 200 moveto
>((98765)25680) token pop show show

>100 300 moveto
>((15)0987654321) token pop show show

>showpage

>George Spowart                    


Apologies, I omitted to include font type and size in above example
George Spowart                    



Fri, 02 May 2003 03:00:00 GMT  
 String manipulation

Quote:

> Anyone know how I can strip characters out of string before printing it?

> The string will be something like "(402)123456787890" and I want to be
> able to strip out the open and close brackets.

Thanks for the suggestions.  The 'token' method was an interesting one which
I must try and remember.  Unfortunately I couldn't that methos because there
could be an indeterminate number of brackets in the string.

However, I took the plunge and managed to figure it out using 'get' and
'put'.

The original code had the following line at the beginning of the proc in
question:

    /msg exch def

Which I replaced with the following code:

    /humantext exch def
    /msgtemp humantext length string def
    /msgidx 0 def

    humantext
    {   dup dup
        40 ne exch 41 ne and
        { msgtemp exch msgidx exch put
          /msgidx msgidx 1 add def }
        { pop } ifelse
    } forall
    /msg msgtemp 0 msgidx 1 sub getinterval def

Seems to do the trick.  If anyone can suggest any improvements then be my
guest.

BTW, if anyone is interested in why I needed this, it's for printing
barcodes along with their human-readable equivalent.  We need the brackets
in the human readable text under the barcode, but the barcode itself cannot
contain them.

Cheers,

Duncan Kinnear.



Sat, 03 May 2003 03:00:00 GMT  
 String manipulation
If you want something simple... if you're always removing a bracketed set
from the BEGINNING of the string, you can do it very easily.

/newstring ((645)8822345-8783457734) def
/newstring oldstring (\)) search {exch pop exch pop} if def

That should do the trick... search returns "pre" "match" "post", and you're
only interested in the "post" part (what comes after the first right bracket
in the string).  Using this, if there is no right bracket in the string, it
will leave the whole string on the top of the stack, which will be defined
as newstring as well.

I haven't actually run this, but it should work "out of the box".

Kevin.

Quote:
----- Original Message -----

Newsgroups: comp.lang.postscript
Sent: Tuesday, November 14, 2000 12:33 PM
Subject: Re: String manipulation


> > Anyone know how I can strip characters out of string before printing it?

> > The string will be something like "(402)123456787890" and I want to be
> > able to strip out the open and close brackets.



Tue, 13 May 2003 03:00:00 GMT  
 String manipulation
OOps... sorry, the first line should read "/oldstring" not "/newstring"


Quote:
> If you want something simple... if you're always removing a bracketed set
> from the BEGINNING of the string, you can do it very easily.

> /newstring ((645)8822345-8783457734) def
> /newstring oldstring (\)) search {exch pop exch pop} if def

> That should do the trick... search returns "pre" "match" "post", and
you're
> only interested in the "post" part (what comes after the first right
bracket
> in the string).  Using this, if there is no right bracket in the string,
it
> will leave the whole string on the top of the stack, which will be defined
> as newstring as well.

> I haven't actually run this, but it should work "out of the box".

> Kevin.

> ----- Original Message -----

> Newsgroups: comp.lang.postscript
> Sent: Tuesday, November 14, 2000 12:33 PM
> Subject: Re: String manipulation


> > > Anyone know how I can strip characters out of string before printing
it?

> > > The string will be something like "(402)123456787890" and I want to be
> > > able to strip out the open and close brackets.



Tue, 13 May 2003 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. String manipulation with vbscript

2. String manipulation topic

3. String manipulation...

4. String manipulation...

5. Text String Manipulation

6. ps string manipulation... ppuulllEEEEEEZZZZZZ

7. Newbie question : string manipulation with VBscript.

8. String manipulation

9. String manipulation help

10. Help for a Newbie: CSV data to be used in string manipulation

11. unicode and ANSI string manipulation repost

12. unicode and ANSI string manipulation

 

 
Powered by phpBB® Forum Software