How To Clean Up Messy Text With TextWrangler

Why Would I Want To Do This?

If you frequently receive text from others for use in your work or projects you probably find that it is often messy, containing extra spaces, misplaced caps, all caps or even no caps. Also, if you grab it from a web page or a Google Doc, your text can contain formatting that can affect how it looks when pasted in to its final home. A good way to remove that formatting as well as to do other text manipulations is to use a good text editor like TextWrangler.

I use TextWrangler for a few reasons, it’s powerful and it’s free. I occasionally think about upgrading to it’s big brother app BBEdit or another editor but with what I do I find TextWrangler works well for me. In this guide I’ll show you how to use some of its built in features to make working with plain text easier and how to save a bunch of time when you have messy text to start with.

Changing Text Case

media_1370459029574.png

You can’t always control in what format you receive your content from others. Each person may have their own method of how they generate it and how they style it. Thankfully TextWrangler makes it easy to handle the most common changes. In this instance we’ve got a paragraph of fully capitalized text (apparently they haven’t read our Guide on How To Disable Your Caps Lock Key) that we want to convert.

  1. First you want to select the text you want to modify. Your keyboard shortcut of command-a will select all the text in your document or you can use your mouse or other method to highlight the affected text. In TextWrangler you can easily select lines or whole paragraps by clicking next to the line numbers in the left gutter area.
  2. Lots of options available for text manipulation on the appropriately named “Text” menu – we want to use the Change Case options here.
  3. Here is where you choose the conversion you want to make be it full case conversion, caplitalize words, sentences or lines. You can click each to see the results and then choose another that may be more suitable.

Remove HTML Formatting

media_1370721735852.png

If you are working with HTML or web based text, you may find that if you copy and paste it from one site and in to another HTML editor it will retain the formatting from the original site. This is because it is copying much more than just the text, it can also have style and formatting information which gets pasted as well. Sometimes this might not even be visible but it can cause all sorts of problems when trying to format or style your newly pasted text.

Some programs do offer you an option to “Paste As Plain Text” which should strip any formatting from your copied text and should alleviate any such issues. If, however, that isn’t an option using a text editor like TextWrangler can serve as an intermediary for you.

In an empty Text Wrangler document it’s a three step process:

  1. Paste your copied text in to the text document using either the menu option or by pressing command-v
  2. Select all of the newly pasted (and cleaned) text using the menu or by pressing command-a
  3. Copy or Cut the selected text using either the menu or by pressing command-c or command-x

Your copy option will leave your text in the TextWrangler document while your cut option will remove the text from your document. Both options will place the text on your system clipboard ready to paste in to your new document.

Remove Extra Spacing

media_1370725278492.png

There are still a lot of people who use the double space at the end of a sentence when creating their content. I much prefer the single space following a period so I like to remove those extraneous spaces and TextWrangler makes it really easy.

  1. Open the Find box from your Search menu or by using the command-f keyboard shortcut.
  2. We’re looking for two spaces in a row in our document. In the Find box go ahead and just hit your space bar twice – you won’t see any character but the cursor will move two spaces.
  3. In the Replace box go ahead and just put in a single space. This is what we are putting in place of the two spaces we found above.
  4. Now that we have the criteria set – to find any instance of two spaces in a row and to replace it with a single space, we can go ahead and click on Replace All. You’ll get a confirmation with the number of instances it has corrected. Much easier than going through sentence by sentence right?

I absolutely recommend choosing a good text editor and getting to know its features. I’ve just scratched the surface here of what sorts of things are possible but even if you are not a programmer or developer, a text editor can be a huge time saver and productivity tool. In future guides we’ll go in to even more automated means to work with text and to do this sort of thing with just a few keystrokes.

What are your favorite text editor tricks?