Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
String handling - from first steps to practical examples

Initial String handling examples on a training course are sometimes a bit mundane - and that's because we have to cover some of the basics like "what is a string" before we start reading them in useful quantities from files, databases, or web resources. But it's important to get those basics understood early - questions like "how do we test for two strings being equal?

Now ... in most languages, you may already know that two equals signs checks equality ... and so you would expect you use that symbol for string equality. And it's surprising how often you would be wrong.
&bull  == will work very nicely in PHP and in Python
but ...
&bull  = is what you use in an SQL WHERE clause
&bull  eq or (more modern) ~~ is what you need in Perl
and some language have functions or methods for the job:
&bull  strcmp is the function in C
&bull  equal is the function in Java ...
and that's because these are pointer based languages,and if you compare with == you're checking for two names pointing at the same memory address, and not looking at two different locations to see if they contain the same thing.

There's a Java example that shows how string comparisons work - [here - ashton.java] - with an explanation too. A further example - [here - purton.java] - shows you a number of other tests on strings in Java - testing to see if they're qual (but ignoring case) or the start or the end of the string. And when we start to manipulate strings, we use functions like indexOf and substring - a further example [here - oaksey.java] and another [here - minety.java].

Moving on, then, really practical and useful string demonstations start once you get on to applications / programs that have a significant flow of data being read - and there's a new Java example from last week [here - Vest.java] that shows that. We've used a BufferedReader and FileReader objects to get a file handle to the data source, line by line, and the readLine method to read the data itself. We're then using indexOf and substring again - but this time with practical good cause - to manipulate the data.

Moving on further, you can start using utility classes such as ArrayLists and HashMaps to hold, count, and manage strings - the example above has been extended to show this [here - Tshirt.java] (I could usefully have demonstrated a StringTokenizer too!) and then to add some good validation checks using excpetions [here - Bikini.java].
(written 2010-11-13)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J714 - Java - Fundamental classes
  [42] Do languages change? - (2004-09-08)
  [1062] Java sorting - comparable v comparator - (2007-02-02)
  [1502] Java, sorting, ArrayList example, generics - (2008-01-11)
  [1910] Java - Generics - (2008-11-27)
  [2323] Java Collection Objects in the java.util package - (2009-08-05)
  [2418] Viv.java uses unchecked or unsafe operations - explanation and cure - (2009-09-24)
  [2421] Sorting Collections of Objects in Java - (2009-09-25)
  [2649] Length, size or capacity in Java? - (2010-02-24)
  [2734] for and foreach in Java - (2010-04-22)
  [2920] Sorting - naturally, or into a different order - (2010-08-14)
  [4330] Java - factory method, encapsulation, hashmap example - (2014-11-27)
  [4396] Java Utility class - flexible replacement for array. Also cacheing in objects and multiple catch clauses example. - (2015-01-16)
  [4421] How healthy are the stars of stage and screen? - (2015-02-09)
  [4431] A Java servlet that is also a stand alone program. And a server that is also a web client. - (2015-02-19)

J712 - Java - Exceptions
  [1066] Final, Finally and Finalize - three special words in Java - (2007-02-05)
  [1875] What are exceptions - Python based answer - (2008-11-08)
  [2420] Exceptions in Java - why and how - (2009-09-24)
  [2622] Handling unusual and error conditions - exceptions - (2010-02-03)
  [2862] Fail Safe Error Handling in Java via Exceptions - (2010-07-09)
  [3045] After Course Resources - do we publish sample answers. Example from Java Exceptions module. - (2010-11-13)
  [4350] Keyboard reader for Java programming newcomers - (2014-12-12)

J707 - Java - Strings
  [1446] An answer to a student asking 'Help' - (2007-11-27)
  [1557] Trying out our Java examples on our web site - (2008-02-27)
  [4393] Splitting Java strings and extracting numbers - (2015-01-13)
  [4414] Java - converting an integer to a fixed length string - (2015-02-04)


Back to
What is a universal superclass? Java / Perl / Python / Other OO languages
Previous and next
or
Horse's mouth home
Forward to
Computer Graphics is fun - even if Java Applets are Old Hat
Some other Articles
Getting your C++ program to run
Positively reforming the system - could it be done?
Views of Melksham - November 2010
Computer Graphics is fun - even if Java Applets are Old Hat
String handling - from first steps to practical examples
What is a universal superclass? Java / Perl / Python / Other OO languages
Java Beans, tag libraries and JSPs - what and why.
Changing a Servlet - more that just editing and compiling
Gathering information - logging - with log4j. First steps.
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3048_Str ... mples.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb