Working with Text

Introduction

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.


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.

  1. Sort the lines in ascending order.
    1. Using the mouse or keyboard, move cursor to the first line and first character.
    2. Using the keyboard press F8, activating block select (see Statusbar Explained).
    3. Move cursor to the last line and last character.
    4. Press F8, deactivating block select.
    5. Open the Sort dialog by selecting Edit menu > Sort (see Sort).
    6. 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';
    
  2. Remove the leading dollar marks.
    1. 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.
    2. Delete selection by, selecting Edit menu > Delete (see Edit Menu).
  3. 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.

    1. Position the right edge so that it is to the right of the longest line (see Mouse control).
    2. Justify Right by selecting Format menu > Block Format > Justify Right (see Block format) or press Ctrl+Alt+Right(see Keyboard shortcuts).
    3. Use Column selection and Delete.
    4. Once complete, make the text Justify left using the Block Format menu or pressing Ctrl+Alt+Left.
  4. Replace [] with () and replace ' with ".
    1. Select all the text.
    2. Open the Replace dialog by selecting Search menu > Replace (see Search and Replace).
    3. 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

  5. Insert the numbering index.
    1. First, select the lines, then presss ATL+I (or click Menu > Edit > Lines Manipulation > Insert Text to Lines) to call the insert dialog out.
    2. Select numbering.
    3. Move the index into the brackets. Press ALT key, and select the first columns.
    4. Press Ctrl+x to cut it to clipboard, then put the cursor into the bracket of the first line. Press Ctrl+v to paste.
  6. Remove extra blank space at the beginning of the lines.
    1. 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.