Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Tcl/Tk module T205
String Handling in Tcl
Exercises, examples and other material relating to training module T205. This topic is presented on public courses Learning to program in Tcl, Tcl Programming, Tcl Programming

The Tcl language is built around strings everything is a string! In this module we look at basic string handling commands, the string command itself which provides a flexible selection of facilities, and we introduce regular expressions for pattern matching.

Related technical and longer articles
Analysing incoming data lines

Articles and tips on this subjectupdated
4455Working out distance between places, using OS grid references and a program in Tcl
In Great Britain, locations have Ordnance Survey grid reference positions which place them to within 100 metres. Our training centre / hotel is at ST907633 - that's   100 km square ST   90.7 km into that square from the west side   63.3 km into that squate from the south ...
4454Everything is a string - even a list
Almost all variables in Tcl are held as strings ... if you use integers and stirings in calculations such as expr and incr. the strings are converted back and forth intergally. Lists, too, are held as strings of characters in which chunks of string are counted / taken out as being elements in the list. ...
4205Regular Expression Substitution - Tcl
regexp matches regular expressions in TCL, and it will return the latest match into a series of variables if you specify their names. regsub matches and replaces... not quite such a common requirement, and perhaps something I haven't blogged about in the past.   set newstory [regsub blue $original ...
3576Tcl - apparently odd behaviour of string trimleft
Question: Why does this code:   set dir "D:/JNN/proc/"   set tempname "D:/JNN/proc/Doc-99887767.dat"   set cname [string trimleft $tempname $dir]   puts $cname report   -99887767.dat but this code:   set dir "D:/JNN/proc/"   set ...
3285Extracting data from a string / line from file - Tcl
I never cease to be amazed at the number of different ways that data can be encoded into simple test lines ... and how the various languages that we teach can be used to manipulate / extract pertinent information. Today, on a Tcl Course, I was presented with data in this form:   T/N/R/Brother/Sister/Mum/Bob.txt/Esmerelda.txt/Sophie.txt The ...
3192Tcl - Some example of HOW TO in handling data files and formats
During the Tcl course I was running earlier this week, we got involved in a number of interesting topics such as • How to clean up input lines into lists of fields (use split) • How to reformat awkward fields (use regexp and regsub) • How to combine files that vary in format from year ...
404How to check that a string contains a number in Tcl
In Tcl, all variables hold strings. If you perform an arithmetic operation such as an expr, an incr or a numeric comparision, the incoming strings are converted into a numbers internally, the calculations are done, and the results are converted back to strings and saved. It might not sound very efficient, ...
2472split and join in tcl and expect
Split and join in most languages convert strings of text into arrays / lists / collections of other sorts. But in Tcl, all variables are held as strings, so are split and join actually needed? If you're working with a collection of single words - no embedded spaces, no special characters, space delimited, ...
1601Replacing the last comma with an and
If I have a list, I'm likely to want to present it comma separated for the most part, but with the word "and" between the last two elements. "Cambridge, the M11, the M25, the M4, the A361 and Melksham" for example. Lists or arrays can be joined in almost any language with a function called join or ...
1410Tcl / regsub - changing a string and using interesting bits
Regexp matches a string to a regular expression, and regsub goes one further in that it replaces the found string with something else, saving the transformed output into a new variable. But what if I want the output pattern to include part of the string that was matched? I can refer to the "interesting ...
1403Square Bracket protection in Tcl
I was writing some string match examples in Tcl yesterday - and had the need to explicitly match square brackets within my string. But I couldn't just write the square brackets into the match string ... • The square bracket first needed protection from the Tcl parser before it even got to the ...
943Matching within multiline strings, and ignoring case in regular expressions
Regular Expressions are powerful matching tools and you can specify almost anything within them. But there are certain facilities that are naturally applied to the regular expression as a whole rather than to parts of the match, and there are specified in a different way in each language / implementation. For ...
779The fragility of pancakes - and better structures
Have you ever hunted around a directory for a file ... you KNOW it's there, but you can't find it - can't see the wood for the trees, if you like, in a listing that spills over many pages? I call such directory structures "pancakes" as they're thin and flat, and they tend not to be very easy to work ...
Examples from our training material
ac_report   Complete example - Access log file analysis
apfo   format and append commands
brax   Literally matching round brackets in regular expressions
ccat   lappend and concat - the difference
datematch   Matching a date using a regular expression
dm2   A further date match example
hunter   Example of analysis of a log file
iconfinder   search for all icon references in a web log
match   String matching - using globing
poco   Postcode identifier and string splitter
rematch   String matching using a regular expression
rf   Opening and reading a file
rf2   Using scan to get a field from a string
rf2a   Using scan's return value
stringinfo   Getting information from a text string
stringman   Manipulating a string
String matching in Tcl
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from [here].
Topics covered in this module
Basic string handling commands.
The string command.
Regular expressions.
The elements of a regular expression.
Manipulating matched regular expressions.
Putting it together.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Tcl/Tk, Expect,Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/T205.html • PAGE BUILT: Mon Feb 8 18:55:24 2016 • BUILD SYSTEM: WomanWithCat