String manipulation... 
Author Message
 String manipulation...

  I'll be danged if I can remember how I did this before...  Anyone got code
to break a string into single character strings with a mark at the
beginning?  For example:

  (foo) -- mark (f) (o) (o)

--

Pongidae, and proud of it.

  No combat ready unit has ever passed inspection.



Wed, 12 Jan 2005 01:55:43 GMT  
 String manipulation...

Quote:

>   I'll be danged if I can remember how I did this before...  Anyone got code
> to break a string into single character strings with a mark at the
> beginning?  For example:

>   (foo) -- mark (f) (o) (o)

/foo_mark            % (foo) -> [ (f) (o) (0)
   { mark exch        % [ (foo)
       { 1 string dup % [ 102 ( ) ( )
         3 2 roll     % [ ( ) ( ) 102
         0 exch       % [ ( ) ( ) 0 102
         put          % [ (f)
       }
     forall
   } bind def

--

Your postscript expert is just a click away.
http://www.quadnet.net/alexcher



Wed, 12 Jan 2005 10:08:17 GMT  
 String manipulation...

Quote:

>   I'll be danged if I can remember how I did this before...  Anyone got code
> to break a string into single character strings with a mark at the
> beginning?  For example:
>   (foo) -- mark (f) (o) (o)

I thought this would be easier than it was:

GS>/split {mark exch {1 string dup 0 4 -1 roll put} forall} def
GS>(foo) split
GS<4>pstack
(o)
(o)
(f)
-mark-
GS<4>
--

Want to use a wheel? Buy one. Want to understand the wheel? Reinvent it.



Wed, 12 Jan 2005 10:44:37 GMT  
 String manipulation...
Repost, not sure if my first reply got lost or not...

Quote:

>   I'll be danged if I can remember how I did this before...  Anyone got code
> to break a string into single character strings with a mark at the
> beginning?  For example:
>   (foo) -- mark (f) (o) (o)

GS>/split {mark exch {1 string dup 0 4 -1 roll put} forall} def
GS>(foo) split pstack
(o)
(o)
(f)
-mark-
GS<4>
--

Want to use a wheel? Buy one. Want to understand the wheel? Reinvent it.


Wed, 12 Jan 2005 11:22:06 GMT  
 String manipulation...

says...

Quote:

>  I'll be danged if I can remember how I did this before...  Anyone got code
>to break a string into single character strings with a mark at the
>beginning?  For example:

While it's always possible that there's a valid, non printing related, reason
for doing something like this in the printer rather than in the originating
app., this sounds like it could be one of those ``if I wanted to get there, I
wouldn't start from here'' questions:-)

If the reason for splitting up strings is anything related to printing
(hit-testing, kerning, fancy typographical effects) or indeed the strings
aren't oging to be printed but might one day be localised, then you should use
the cshow operator.  If you don't use cshow, then the first time someone tries
to run your code on a Japanese printer, you'll likely have to spend months
re-writing your code.  If you do use cshow, you won't.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ian Kemmish                   18 Durham Close, Biggleswade, Beds SG18 8HZ, UK

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
``Behind every successful organisation stands one person who knows the secret
  of how to keep the managers away from anything truly important.''



Fri, 14 Jan 2005 15:03:10 GMT  
 String manipulation...

Quote:
> Anyone got code to break a string into single character
> strings with a mark at the beginning?

One possibility that does allocate VM for string storage but uses substring
of the original instead :

% <string> s_p_l_i_t [ <ch0> <ch1> ... <chn>
% s_p_l_i_t creates N one-character substrings of <string>,
% one for each character. Substrings are placed on stack in
% order they appaear in <string> and are shared with the
% original <string> (thus no extra allocation is done)

/s_p_l_i_t {
  mark exch        % [ <string> 1
  dup length 1 sub 0 1
  3 -1 roll        % [ <string> 0 1 <len>
  {                % [ ... <string> <i>
    1 index exch 1 % [ ... <string> <string> <i> 1
    getinterval    % [ ... <string> <ch[i]>
    exch
  } for
  pop              % remove <string> from top

Quote:
}bind def

_______________________________________________________
Fran?ois Robert
(to mail me, reverse character order in reply address)


Fri, 14 Jan 2005 15:47:48 GMT  
 String manipulation...

Quote:
> While it's always possible that there's a valid, non printing related,
reason
> for doing something like this in the printer rather than in the
originating
> app., this sounds like it could be one of those ``if I wanted to get
there, I
> wouldn't start from here'' questions:-)

  Hint: you've used ``printer'' where you meant ``PostScript interpreter''.
:-)

--

Pongidae, and proud of it.

  All the best people in life seem to like Linux.
                                                        -- Steve Wozniak



Sat, 15 Jan 2005 00:42:04 GMT  
 String manipulation...

Quote:
> I thought this would be easier than it was:

  :-)

Quote:
> GS>/split {mark exch {1 string dup 0 4 -1 roll put} forall} def

  Oh right, strings are composite.  <sigh>  Thanks.  :-)

--

Pongidae, and proud of it.

  Theists think all gods but theirs are false.  Atheists simply don't
make an exception.



Sat, 15 Jan 2005 00:48:19 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