Tip on searching for and replacing the tab non-printing character

1 view
Skip to first unread message

Paul Merrell

Sep 26, 2023, 1:37:36 AM9/26/23
to Notecase Pro
Recording this because I acquired a mental block that took me a couple
of hours to dismantle before I figured this out so hopefully this will
save someone else from the same fate.

Use case: I've had an old collection of embedded scripts that had
their code indents done as tabs. I wanted to replace each tab in the
document with two spaces. But NoteCase Pro's text search doesn't
recognize a tab as a character that can be searched for or replaced.

The solution is to use a RegEx search in the Replace dialog and
representing the tab character with the C-like escape sequence "\t"
(without the quotes) and the spaces as themselves, " " (without the

The same representations also work in Lua, so a script to do such
replacements could be quickly cobbled together using the global
substitution routine:

s = utf8gsub (s, \t, " ")

or if you also want to know how many replacements were made:

local nHowMany = nil
s, nHowMany = utf8gsub (s, \t, " ")
Nc_GUI_Infobox(nHowMany, 0, "Info")

See Help file > Automation, Scripts and Plugins > Scripting NoteCase
Pro > Integrated Lua Libraries > Lua-utf8 > Routines Substituting for
Lua Routines > utf8ex.gsub, and

Help file > Automation, Scripts and Plugins > Scripting NoteCase Pro >
Scriptable Program Commands > GUI Commands > GUI Windows for Scripts
Only > Nc_GUI_InfoBox.

Best regards,


[Notice not included in the above original message: The U.S. National
Security Agency neither confirms nor denies that it intercepted this
Reply all
Reply to author
0 new messages