Show invisible characters (tab, space, return) in field

hh hh at hyperhh.de
Sat Dec 8 09:21:49 EST 2018


> Kaveh wrote:
> What I am looking for is a native replacement of a return, say,
> with a visible characters wherever it appears. 

You have to replace return with <visibleChar>&return if you wish
to preserve the line breaks.

Similarly
• have you to replace space with <visibleChar>&space if you wish
to preserve the word breaks,
• have you to replace tab with <visibleChar>&tab if you wish
to preserve the indents.

You could use unicodeChars for such a making of "whitespace" visible.
If you do it in a variable this is very fast, slower but still fast
for making such "whitespace" (space, tab, return) again invisible.

Of course this removes any styling from the variable. If you need to
preserve styles then you could try
"replace in field <preserving|replacing> styles".
But then it becomes very slow.

Here the fast unicode-symbols-in-variable method. It has moreover the
advantage that you can copy and paste such "visible-whitespace-text".

on mouseUp b
  put the millisecs into m1
  lock screen; lock messages
  put fld 1 into txt
  put numToCodePoint(0x00B7)&numToCodePoint(0x200A) into s0
  put numToCodePoint(0x23CE)&cr into c0
  put numToCodePoint(0x21E5)&tab into t0
  if b=3 then
    replace tab with t0 in txt
    replace cr with c0 in txt
    replace space with s0 in txt
  else
    replace s0 with space in txt
    replace c0 with cr in txt
    replace t0 with tab in txt
  end if
  put txt into fld 1
  put the millisecs - m1 into fld "timing"
end mouseUp

Note.
The above is *VERY* basic. Your text could also contain other variants
of tabs (right, left ...), spaces (unicode spaces, e.g. non-breaking)
and returns (mixed LF/CR, paragraph signs).







More information about the Use-livecode mailing list