Runtime Revolution
 
Articles Other News

Revolution Workshops: Part One, Working with Text


by Runtime Revolution Staff

As part of our ongoing initiative to improve the materials available to new users of Revolution, we have recently created a series of workshops which are made available to new downloaders of Revolution. Here at the editorial desk, we felt that more members of the community could benefit from having access to these tutorials, so we will be featuring them here for the next few editions. New users, old users, even old pro users of Revolution are bound to learn new things and smarter ways of working from these handy little workshops.

download text workshop

Analyzing and processing text data is perhaps the most common task performed in any programming language. Emails, database entries, XML and HTML - they are all text. In Revolution, processing text is not only easy, but fast. In fact, we believe our text processing capabilities are among the most powerful of any programming language.

Lines, words, items, characters

Revolution understands text in the same way you do. You can refer to words within a block of text in the same way you would in natural language. This makes it quick and easy to write code that handles text and it means you can read and understand that code months later - long after you have forgotten all the details about what your code does.

text screenshot

 

The power of simplicity

Highlights

Analyze

Word count...
put the number of words in field "text"

Performing an action if an item in some comma separated text is a number...
if item 2 of line 3 of myCSVList is a number then doProcess

Construct

Extract two lines and insert them into another piece of text...
put line 2 to 4 of myText after line 6 of newText

Construct a new comma separated list from some items in an existing one...
put the first item of myText, item 3 of myText, the last item of myText into newList

Extract

Do something if a search term is found...
if "search term" is in line 3 of myText then doSomething

Extract the second word of each line...
repeat for each line L in T
put word 2 of L & cr after N
end repeat
put N into field "output"

Format

Replace some text with something else...
replace x with y in field "text"

Check if text fits onto the display...
if the formattedWidth of field "display" > the width of field "display" then cutTextToFit

Sort lines of some text in date order, where the date is the third word on each line...
sort lines of myList dateTime by word 3 of each

Underneath the simplicity of Revolution's text capabilities lies power. Revolution can handle even the most complex text operations. Advanced features include full support for "regular expressions," arrays and a fast XML library. Whether you want to extract some data quickly from a lot of small text files or analyze hundreds of megabytes of log files, Revolution can handle it all.

The benefit of these so-called "chunk expressions" is that you don't have to write complicated formulas to find the bit of information you're interested in. You can also combine them with powerful adjectives like "first" and "last." No need to count the number of characters, words, or lines in the text you're analyzing. Just specify "the last line," for example, and you're done.

Items are another incredibly flexible "chunk" marker. By default they are indicated by commas, but you can change the item delimiter to a tab or any other character. That makes parsing data a snap in all kinds of situations.

Revolution's unique way of referencing text elements means that you spend less time on the error-prone tedium or "re-inventing the wheel" and therefore can develop your solutions faster than in any other language.

Interactive Workshop: Learn How, Now

Try out text in Revolution right now. We show you how to complete several common tasks. As your understanding grows, you can change the examples and see the effects right within the workshop, or just drop the example code into a new project and create something completely new.

Get it now from within Revolution by opening the Message Box from the toolbar then pasting in the following and pressing return:

go stack URL "http://www.runrev.com/ws/text.rev"

Or you can get it by downloading it from:

http://www.runrev.com/ws/text.zip

We hope you find this useful, don't miss the next installment in the series, which will explore working with multimedia.

 
©2005 Runtime Revolution Ltd, 15-19 York Place, Edinburgh, Scotland, UK, EH1 3EB.
Questions? Email info@runrev.com for answers.