PSPad is a powerful application with dozens of tools.
With all the tools at our disposal it sometimes
can be difficult determining how to use all of them.
This topic will introduce some of PSPad's text manipulation tools by example.
Have you ever needed to number a 1000 lines, add bullets, or add text at line
begin or end?
Let us first look at the requirement. Below is an array of
fruits the came from an aged PHP script and our boss needs it convert to ASP,
sorted, and duplicates removed; ASAP.
Example text
$fruit[] = 'Strawberry';
$fruit[] = 'Pear';
$fruit[] = 'Peaches';
$fruit[] = 'Grape';
$fruit[] = 'Apple';
$fruit[] = 'Peaches';
$fruit[] = 'Crabapple';
The most obvious way to do this is adjust the text all manually,
but consider it we very well could have hundreds of lines.
Let us see what PSPad can do to fix this mess.
- Sort the lines in ascending order.
- Using the mouse or keyboard, move cursor to the first line and first character.
- Using the keyboard press F8, activating block select (see Statusbar Explained).
- Move cursor to the last line and last character.
- Press F8, deactivating block select.
- Open the Sort dialog by selecting Edit menu > Sort (see Sort).
- Set direction as Ascending, sort by as ANSI value and check Remove Duplicates. Select OK.
Step 1.
$fruit[] = 'Apple';
$fruit[] = 'Crabapple';
$fruit[] = 'Grape';
$fruit[] = 'Peaches';
$fruit[] = 'Pear';
$fruit[] = 'Strawberry';
- Remove the leading dollar marks.
- Select the first columns using the Column selection function. Holding the ALT key,
dragging the cursor from line 1, column 1 to line 6, column 2.
- Delete selection by, selecting Edit menu > Delete (see Edit Menu).
- Remove the semicolons
If we can move all the semicolons into the same column, we can remove them by
Column selection, just as we removed the dollar signs.
- Position the right edge so that it is to the right of the longest line (see Mouse control).
- Justify Right by selecting
Format menu > Block Format > Justify Right
(see Block format) or press Ctrl+Alt+Right(see Keyboard shortcuts).
- Use Column selection and Delete.
Once complete, make the text Justify left using the Block Format menu
or pressing Ctrl+Alt+Left.
Replace [] with () and replace ' with ".
- Select all the text.
- Open the Replace dialog by selecting Search menu > Replace (see Search and Replace).
- Using this dialog box you may now preform the replace.
Step 1.
fruit() = "Apple"
fruit() = "Crabapple"
fruit() = "Grape"
fruit() = "Peaches"
fruit() = "Pear"
fruit() = "Strawberry"
You may worry that if there are also [] and ' in the
string, they will be replaced wrongly. Regular express can help us to
avoid this trouble. For more information about regular express, please
read the help documents about Search/Replace
Insert the numbering index.
- First, select the lines, then presss ATL+I (or click Menu > Edit > Lines Manipulation > Insert
Text to Lines) to call the insert dialog out.
- Select numbering.
- Move the index into the brackets. Press ALT key, and select the first columns.
- Press Ctrl+x to cut it to clipboard, then put the cursor into the
bracket of the first line. Press Ctrl+v to paste.
Remove extra blank space at the beginning of the lines.
- Use column selection again, you can delete them easily.
PSPad provide a lot of functions to deal with the text. Some are
obvious and some need your exploring. Once you are familiar with it, your
work will be much more efficient.